Skip to content

πŸ”— 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 using ResponseModel.

    β€’ 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