flask_more_smorest.error.error_handlers

Error handlers for Flask-More-Smorest.

This module provides error handler functions and a RequestHandlers class for registering error handlers with Flask applications.

Functions

handle_api_exception(e)

Handle ApiException and its subclasses.

handle_db_exception(e)

Handle database exceptions.

handle_generic_exception(e)

Handle generic Python exceptions.

server_error_handler(e)

Handle unhandled server errors.

unauthorized_handler(e[, errors, level, ...])

Handle unauthorized access errors.

Classes

RequestHandlers([app])

Handler class for registering error handlers with Flask.

flask_more_smorest.error.error_handlers.server_error_handler(e)[source]

Handle unhandled server errors.

Parameters:

e (Exception) – The exception that was raised

Return type:

Response

Returns:

Flask Response with error details

flask_more_smorest.error.error_handlers.unauthorized_handler(e, errors=None, level='info', warnings=None)[source]

Handle unauthorized access errors.

Parameters:
  • e (Exception) – The exception that was raised

  • errors (dict[str, str] | None) – Optional error details

  • level (str) – Logging level to use

  • warnings (list[str] | None) – Optional warning messages

Return type:

Response

Returns:

Flask Response with error details

flask_more_smorest.error.error_handlers.handle_api_exception(e)[source]

Handle ApiException and its subclasses.

Parameters:

e (ApiException) – The API exception to handle

Return type:

Response

Returns:

Flask Response with error details

flask_more_smorest.error.error_handlers.handle_generic_exception(e)[source]

Handle generic Python exceptions.

Parameters:

e (Exception) – The exception to handle

Return type:

Response

Returns:

Flask Response with error details or original HTTP response

flask_more_smorest.error.error_handlers.handle_db_exception(e)[source]

Handle database exceptions.

Automatically rolls back the database session before generating the error response.

Parameters:

e (DatabaseError) – The database error to handle

Return type:

Response

Returns:

Flask Response with error details

class flask_more_smorest.error.error_handlers.RequestHandlers(app=None)[source]

Handler class for registering error handlers with Flask.

This class provides a simple way to register all error handlers with a Flask application.

Example

>>> from flask import Flask
>>> from flask_more_smorest.error import RequestHandlers
>>>
>>> app = Flask(__name__)
>>> handlers = RequestHandlers(app)
__init__(app=None)[source]

Initialize request handlers.

Parameters:

app (Flask | None) – Optional Flask application to register handlers with

init_app(app)[source]

Register error handlers with Flask application.

Parameters:

app (Flask) – Flask application to register handlers with

Return type:

None