API Exception

The APIException is the root exception that you should inherit for errors that are thrown within action functions. This syntax allows your frontend to pick up on the error parameters. APIExceptions are just Pydantic BaseModels with a few helpful defaults, and a metaclass that allows them to work natively with HTTPExceptions.

CLASSmountaineer.exceptions.APIException

Base class for user defined APIExceptions that can be thrown in server actions and should provide some metadata back to the client caller.

Code

class PostNotFound(APIException): status_code: int = 404 detail: str = "The post was not found" post_id: int is_deleted: bool class MyController(ControllerBase): @passthrough def get_post(self, post_id: int) -> Post: post = self.post_service.get_post(post_id) if not post: raise PostNotFound(post_id=post_id, is_deleted=True) return post

Class Constructor

  • Name
    kwargs
    Type
    Any
    Description

    Default: {}

Class Attributes

  • Name
    status_code
    Type
    int
    Description
  • Name
    detail
    Type
    str
    Description
  • Name
    headers
    Type
    dict[str, str]
    Description
  • Name
    InternalModel
    Type
    Type[APIExceptionInternalModelBase]
    Description
  • Name
    internal_model
    Type
    APIExceptionInternalModelBase
    Description