duck.contrib.responses.errors

Helpers for fast response generation.

Module Contents

Functions

get_404_error_response

Returns HttpNotFoundError Response for the request.

get_bad_gateway_error_response

Returns the appropriate Bad Gateway response.

get_bad_request_error_response

Returns HttpBadRequest Response for the request.

get_debug_error_as_html

Returns the exception as html (only if DEBUG=True, else None).

get_method_not_allowed_error_response

Returns HttpMethodNotAllowed Response for the request.

get_server_error_response

Returns HttpServerError Response for the provided exception.

get_timeout_error_response

Returns the request timeout error response.

Data

debug_error_style

API

duck.contrib.responses.errors.debug_error_style = <Multiline-String>
duck.contrib.responses.errors.get_404_error_response(request: duck.http.request.HttpRequest)

Returns HttpNotFoundError Response for the request.

duck.contrib.responses.errors.get_bad_gateway_error_response(exception: Optional[Exception], request: Optional = None)

Returns the appropriate Bad Gateway response.

Parameters:
  • exception – The exception which might have caused this.

  • response. (The exception may be included in)

  • request – The current http request.

duck.contrib.responses.errors.get_bad_request_error_response(exception: Exception, request: Optional[duck.http.request.HttpRequest] = None)

Returns HttpBadRequest Response for the request.

Parameters:
  • exception – The appropriate exception.

  • request – The http request.

duck.contrib.responses.errors.get_debug_error_as_html(exception: Exception, request: Optional = None)

Returns the exception as html (only if DEBUG=True, else None).

duck.contrib.responses.errors.get_method_not_allowed_error_response(request: duck.http.request.HttpRequest, route_info: Optional[Dict[str, Any]] = None)

Returns HttpMethodNotAllowed Response for the request.

Parameters:
  • request – The http request.

  • route_info – The route info for the request obtained by RouteRegistry.

duck.contrib.responses.errors.get_server_error_response(exception: Exception, request: Optional = None)

Returns HttpServerError Response for the provided exception.

duck.contrib.responses.errors.get_timeout_error_response(timeout: Optional[Union[int, float]]) duck.http.response.HttpRequestTimeoutResponse

Returns the request timeout error response.

Parameters:

timeout – The timeout in seconds.