π API Reference¶
This page lists the main classes, utilities, and helpers youβll use when working with APIException in your FastAPI project.
Use this as a quick lookup when you want to check arguments, defaults, or core methods.
β Available Exports¶
ResponseModel¶
π What it is:
A generic, strongly-typed Pydantic model that standardizes all API responses.
- β Where to import:
from APIException import ResponseModel
-
β Key Fields:
β’
data
: your payloadβ’
status
: SUCCESS, WARNING, FAILβ’
message
: short summaryβ’
error_code
: only set for failuresβ’
description
: extra context for debugging
message
and status
are Required fields and the rest is Optional.
APIException¶
π What it is:
Your main custom exception class β use this to raise predictable, documented API errors.
- β Where to import:
from APIException import APIException
-
β Key Args:
β’
error_code
: your BaseExceptionCode enumβ’
http_status_code
: maps to HTTP status
BaseExceptionCode¶
π What it is:
Base class for defining your custom business exception codes.
- β Where to import:
from APIException import BaseExceptionCode
APIResponse¶
π What it is: A helper to document your Swagger/OpenAPI responses easily.
-
β Where to import:
from APIException import APIResponse
-
β Usage:
β’
APIResponse.default()
β adds standard 400β500 errors.β’
APIResponse.custom()
β add your own error codes with status.
register_exception_handlers¶
π What it is:
Sets up global handlers to catch APIException and unexpected errors.
-
β Where to import:
from APIException import register_exception_handlers
-
β Key Options:
β’
use_response_model
: bool (default True) | Return responses usingResponseModel
.β’
use_fallback_middleware
: bool (default True) | Catch unhandled exceptions and return a consistent fallback.
β‘ Example¶
Hereβs how a typical setup might look:
from APIException import (
APIException,
BaseExceptionCode,
ResponseModel,
APIResponse,
register_exception_handlers
)
π Next¶
βοΈ Havenβt seen how to integrate yet?
Go to π Installation
βοΈ Want a quick end-to-end setup?
Check out β‘ Quick Start
βοΈ See how to extend this with your own codes:
Read ποΈ Custom Exception Codes