wsgi_tools.error module

Catches any Exception and returns that an error occured.

This is required by many other modules of this package.

class wsgi_tools.error.ErrorHandler(app)

Bases: object

A WSGI-app which executes another WSGI-App and handles exceptions, if they occur.

If the exception is no HTTPException, an HTTPException with the code 500, the message 'A server error occurred. Please contact an administrator.' and the exc_info will be taken.

This is an abstract class. The handle method needs to be overwritten.

Parameters

app – The WSGI-app, which is called by the ErrorHandler

abstract handle(e)

Abstract methed, which has an exception as an arg and returns a body and a list of headers.

class wsgi_tools.error.HTMLErrorHandler(app)

Bases: wsgi_tools.error.ErrorHandler

An ErrorHandler which returns the error in viewable html format.

handle(e)

Abstract methed, which has an exception as an arg and returns a body and a list of headers.

exception wsgi_tools.error.HTTPException(code, message=None, exc_info=None, headers=[])

Bases: Exception

A Exception which says, what status-code and what message should be displayed.

Parameters
  • code (int | str) – The status-code of this Exception

  • message (str, optional) – The message of the error.

  • exc_info (optional) – sys.exc_info() if raised because of another exception.

  • headers (list(tuple), optional) – specific headers for this exception

class wsgi_tools.error.JSONErrorHandler(*args, friendly=False, **kwargs)

Bases: wsgi_tools.error.ErrorHandler

An ErrorHandler which returns the error in the json-body.

Parameters
  • friendly (bool, optional) – If true, the output will be human readable, else (default), the output will be minimal.

  • *args – The args of ErrorHandler

  • *kwargs – The kwargs of ErrorHandler

handle(e)

Abstract methed, which has an exception as an arg and returns a body and a list of headers.