Exceptions API#

Public exception hierarchy for FastAPI-Restly.

Two families:

  • Configuration-time errors (RestlyError / RestlyConfigurationError) raised when the framework is misused before/at setup.

  • Request-time HTTP errors (NotFound / Forbidden / Conflict / BadQueryParam) raised while handling a request. These subclass fastapi.HTTPException, so the default responses are identical to raising HTTPException directly – but a user can app.add_exception_handler(fr.exc.NotFound, ...) to reshape Restly’s errors distinctly (e.g. into RFC 7807 problem+json).

exception fastapi_restly.exc.BadQueryParam(detail: object | None = None, **kwargs: object)#

Bases: RestlyHTTPError

HTTP 400 – an invalid filter/sort/pagination query parameter.

default_detail: str = 'Invalid query parameter'#
status_code: int = 400#
exception fastapi_restly.exc.Conflict(detail: object | None = None, **kwargs: object)#

Bases: RestlyHTTPError

HTTP 409 – the request conflicts with the current resource state.

default_detail: str = 'Conflict'#
status_code: int = 409#
exception fastapi_restly.exc.Forbidden(detail: object | None = None, **kwargs: object)#

Bases: RestlyHTTPError

HTTP 403 – the request is not authorized.

default_detail: str = 'Forbidden'#
status_code: int = 403#
exception fastapi_restly.exc.NotFound(detail: object | None = None, **kwargs: object)#

Bases: RestlyHTTPError

HTTP 404 – the requested resource does not exist (or is not visible).

default_detail: str = 'Not found'#
status_code: int = 404#
exception fastapi_restly.exc.RestlyConfigurationError#

Bases: RestlyError

Raised when Restly is used before required configuration is available.

exception fastapi_restly.exc.RestlyError#

Bases: Exception

Base class for FastAPI-Restly framework errors.

exception fastapi_restly.exc.RestlyHTTPError(detail: object | None = None, **kwargs: object)#

Bases: HTTPException

Base for Restly’s request-time HTTP errors. Subclasses set a status.

default_detail: str = 'Error'#
status_code: int = 500#
exception fastapi_restly.exc.RestlyMisuseWarning#

Bases: UserWarning

Emitted at view registration for common framework-misuse patterns.

Opt-in: enable with fr.configure(warn_on_misuse=True). When a view class is registered via include_view, the framework then flags the three dominant misuses – overriding a route shell (<verb>_endpoint) where a business-verb override was meant, calling session.commit() directly in a view method, and hand-rolling a CRUD route set on a bare View instead of subclassing RestView / AsyncRestView.

exception fastapi_restly.exc.RestlyUncommittedChangesWarning#

Bases: UserWarning

Emitted when a request finishes with uncommitted changes in the session.

The write handlers own the commit, so a custom write route that flushes (e.g. via save_object) but never commits has its changes silently rolled back when the session closes. The fix is almost always to commit: bracket the mutation with write_action(...) (the framework then runs the commit), or reuse a handle_<verb> handler. A route that intentionally rolls back (a validate-then-rollback dry run) can suppress the warning for just that request with session.info["_fr_suppress_uncommitted"] = True.

See also

Shape Error Responses — which exception to raise where, and app-wide error envelopes.