Error handling

exception pyrs.resource.errors.ClientError(*args, **details)[source]

Bases: pyrs.resource.errors.Error

Generic Client Error. Normally the client errors have 4xx status codes.

status = 400
class pyrs.resource.errors.DetailsSchema(extend=None, **attrs)[source]

Bases: pyrs.schema.types.Object

Details part of the error schema. Additional properties possible.

_attrs = OrderedDict([('additional', True)])
_definitions = None
_fields = OrderedDict([('traceback', <pyrs.schema.types.Array object at 0x7ff88c297da0>), ('args', <pyrs.schema.types.Array object at 0x7ff88c2a10f0>)])
exception pyrs.resource.errors.Error(*args, **details)[source]

Bases: Exception

This is the base exception of this framework. The response based on this exception will be a JSON data

description = None

Description of error. Should give details about the error In the message it will appearing as error_description

details = None

None used as empty dict. Gives extra information about this error which could be parsed by the consumer of API.

error = None

Error code should be a string. If it’s not specified the class fully qualified name will be used

get_details(debug=False)[source]

Gives back detailed information about the error and the context. By default its an empty dictionary. The debug depends on the debug parameter should give back traceback information and the positional arguments of the exception. As this is part of the message should conform with the ErrorSchema.

get_headers()[source]

This method gives back the header property by default or an empty dict, but you can override, then provide special headers based on the context

get_message(debug=False)[source]

Should give back a dictionary which will be threated the response body. The message should be conform with the ErrorSchema.

get_status()[source]

This method gives back the status property by default which will be threated as HTTP status code. You can override, then provide your own status code based on the context.

headers = None

HTTP Response headers, (default None processed as empty)

schema = None

You can specify your schema class for validating your message By default the application default error schema the ErrorSchema will be used

status = 500

HTTP status code (default=500)

uri = None

Reference for this error. You can pointing out a documentation which gives more information about how could this error happen and how could be possible to avoid

classmethod wrap(original)[source]

Wraps the exception gives back an Error instance. The created Error instance error property will be updated by the fully qualified name of the original exception. You could use it for Error instances as well, though is not recommended.

class pyrs.resource.errors.ErrorResponse(content, app=None, opts=None, request=None)[source]

Bases: pyrs.resource.response.Response

setup()[source]
class pyrs.resource.errors.ErrorSchema(extend=None, **attrs)[source]

Bases: pyrs.schema.types.Object

Describe how the error response should look like. Goal of this schema is a minimalistic but usable error response.

_attrs = OrderedDict([('additional', False)])
_definitions = None
_fields = OrderedDict([('error', <pyrs.schema.types.String object at 0x7ff88c2a1128>), ('error_description', <pyrs.schema.types.String object at 0x7ff88c2a11d0>), ('error_uri', <pyrs.schema.types.String object at 0x7ff88c2a1208>), ('message', <pyrs.schema.types.String object at 0x7ff88c2a1240>), ('details', <pyrs.resource.errors.DetailsSchema object at 0x7ff88c2a1278>)])
dump(ex)[source]
exception pyrs.resource.errors.InputValidationError(*args, **details)[source]

Bases: pyrs.resource.errors.Error

error = 'invalid_request_format'
status = 400
exception pyrs.resource.errors.ValidationError(*args, **details)[source]

Bases: pyrs.resource.errors.Error

error = 'validation_error'
status = 500