sanic.errorpages.BaseRenderer#

Base class that all renderers must inherit from.

class BaseRenderer(request: Request, exception: Exception, debug: bool)

This class defines the structure for rendering objects, handling the core functionality that specific renderers may extend.

Parameters
request
Request

The incoming request object that needs rendering.

exception
Exception

Any exception that occurred and needs to be rendered.

debug
bool

Flag indicating whether to render with debugging information.

request
Request

The incoming request object that needs rendering.

exception
Exception

Any exception that occurred and needs to be rendered.

debug
bool

Flag indicating whether to render with debugging information.

full#

Provide a formatted message that has all details and is mean to be used primarily for debugging and non-production environments.

def full(self): -> HTTPResponse

Return
HTTPResponse

The response object.

headers#

The headers to be used for the response.

@property
def headers(self): -> t.Dict[str, str]

minimal#

Provide a formatted message that is meant to not show any sensitive data or details.

def minimal(self): -> HTTPResponse

This is the default fallback for production environments.

Return
HTTPResponse

The response object.

render#

Outputs the exception as a response.

def render(self): -> HTTPResponse

Return
HTTPResponse

The response object.

status#

The status code to be used for the response.

@property
def status(self)

text#

The text to be used for the response.

@property
def text(self)

title#

The title to be used for the response.

@property
def title(self)

sanic.errorpages.HTMLRenderer#

Render an exception as HTML.

Inherits from: BaseRenderer

class HTMLRenderer(request: Request, exception: Exception, debug: bool)

The default fallback type.

full#

Provide a formatted message that has all details and is mean to be used primarily for debugging and non-production environments.

def full(self): -> HTTPResponse

Return
HTTPResponse

The response object.

headers#

The headers to be used for the response.

@property
def headers(self): -> t.Dict[str, str]

minimal#

Provide a formatted message that is meant to not show any sensitive data or details.

def minimal(self): -> HTTPResponse

This is the default fallback for production environments.

Return
HTTPResponse

The response object.

render#

Outputs the exception as a response.

def render(self): -> HTTPResponse

Return
HTTPResponse

The response object.

status#

The status code to be used for the response.

@property
def status(self)

text#

The text to be used for the response.

@property
def text(self)

title#

The title to be used for the response.

@property
def title(self)

sanic.errorpages.JSONRenderer#

Render an exception as JSON.

Inherits from: BaseRenderer

class JSONRenderer(request: Request, exception: Exception, debug: bool)

full#

Provide a formatted message that has all details and is mean to be used primarily for debugging and non-production environments.

def full(self): -> HTTPResponse

Return
HTTPResponse

The response object.

headers#

The headers to be used for the response.

@property
def headers(self): -> t.Dict[str, str]

minimal#

Provide a formatted message that is meant to not show any sensitive data or details.

def minimal(self): -> HTTPResponse

This is the default fallback for production environments.

Return
HTTPResponse

The response object.

render#

Outputs the exception as a response.

def render(self): -> HTTPResponse

Return
HTTPResponse

The response object.

status#

The status code to be used for the response.

@property
def status(self)

text#

The text to be used for the response.

@property
def text(self)

title#

The title to be used for the response.

@property
def title(self)

sanic.errorpages.TextRenderer#

Render an exception as plain text.

Inherits from: BaseRenderer

class TextRenderer(request: Request, exception: Exception, debug: bool)

full#

Provide a formatted message that has all details and is mean to be used primarily for debugging and non-production environments.

def full(self): -> HTTPResponse

Return
HTTPResponse

The response object.

headers#

The headers to be used for the response.

@property
def headers(self): -> t.Dict[str, str]

minimal#

Provide a formatted message that is meant to not show any sensitive data or details.

def minimal(self): -> HTTPResponse

This is the default fallback for production environments.

Return
HTTPResponse

The response object.

render#

Outputs the exception as a response.

def render(self): -> HTTPResponse

Return
HTTPResponse

The response object.

status#

The status code to be used for the response.

@property
def status(self)

text#

The text to be used for the response.

@property
def text(self)

title#

The title to be used for the response.

@property
def title(self)

sanic.errorpages.check_error_format#

Check that the format is known.

def check_error_format(format)

sanic.errorpages.escape#

Minimal HTML escaping, not for attribute values (unlike html.escape).

def escape(text)

sanic.errorpages.exception_response#

Render a response for the default FALLBACK exception handler.

def exception_response(request: Request, exception: Exception, debug: bool, fallback: str, base: t.Type[BaseRenderer], renderer: t.Optional[t.Type[BaseRenderer]] = None): -> HTTPResponse

sanic.errorpages.guess_mime#

Guess the MIME type for the response based upon the request.

def guess_mime(req: Request, fallback: str): -> str