Error handling

This module collects various exceptions that may be thrown when communication with a RestAuth server. The exceptions are collected here because the RestAuth server <https://server.restauth.net> also uses these exceptions for error handling. The multi-level inheritance of the exceptions in these modules allows you to:

Also see below for a full example.

RestAuthException

In general, all exceptions thrown by code related to RestAuth are a subclass of this exception:

exception RestAuthCommon.error.RestAuthException[source]

Common base class for all RestAuth related exceptions. All exceptions in this module are a subclass of this exception.

RestAuthException subclasses

The direct subclasses of RestAuthException represent different types of problems and are never thrown directly. Instead, subclasses are thrown to indicate the exact problem. You can use these exceptions to catch an entire type of problem and handle all subclasses collectively. Please also see the example.

exception RestAuthCommon.error.RestAuthImplementationException[source]

Bases: RestAuthCommon.error.RestAuthException

Base class for errors that should not occur in a production environment. If you ever catch such an exception, it is most likely due to a buggy client or server implementation.

exception RestAuthCommon.error.RestAuthSetupException[source]

Bases: RestAuthCommon.error.RestAuthException

Base class for errors that should not occur in a production environment that is correctly configured.

exception RestAuthCommon.error.RestAuthError[source]

Bases: RestAuthCommon.error.RestAuthException

Base class for exceptions related to input coming from the client application.

exception RestAuthCommon.error.RestAuthRuntimeException[source]

Bases: RestAuthCommon.error.RestAuthException

Base class for exceptions that may occur at runtime but are not related to user input. Any subclass of this exception may be thrown by every method that interacts with the RestAuth service.

exception RestAuthCommon.error.ContentTypeException[source]

Bases: RestAuthCommon.error.RestAuthSetupException

Meta-class for Content-Type related exceptions.

Concrete exceptions

Exceptions related to RestAuth communication.

exception RestAuthCommon.error.BadRequest[source]

Bases: RestAuthCommon.error.RestAuthImplementationException

Thrown when RestAuth was unable to parse/find the required request parameters.

On a protocol level, this represents HTTP status code 400.

exception RestAuthCommon.error.InternalServerError[source]

Bases: RestAuthCommon.error.RestAuthRuntimeException

Thrown when the RestAuth service has an Internal Server Error (HTTP status code 500).

exception RestAuthCommon.error.MarshalError[source]

Bases: RestAuthCommon.error.RestAuthImplementationException

Thrown if data can’t be marshalled.

exception RestAuthCommon.error.NotAcceptable[source]

Bases: RestAuthCommon.error.ContentTypeException

The current content type is not acceptable to the RestAuth service.

On a protocol level, this represents HTTP status code 406.

exception RestAuthCommon.error.PreconditionFailed[source]

Bases: RestAuthCommon.error.RestAuthError

Thrown when the submitted data was unacceptable to the system. This usually occurs when the username is invalid or the password is to short.

On a protocol level, this represents HTTP status code 412.

exception RestAuthCommon.error.ResourceConflict[source]

Bases: RestAuthCommon.error.RestAuthError

Thrown when trying to create a resource that already exists.

On a protocol level, this represents HTTP status code 409.

exception RestAuthCommon.error.ResourceNotFound(response)[source]

Bases: RestAuthCommon.error.RestAuthError

Thrown when a queried resource is not found.

get_type()[source]

Get the type of the queried resource that wasn’t found.

See the specification for possible values.

Returns:The resource type that causes this exception.
Return type:str
exception RestAuthCommon.error.Unauthorized[source]

Bases: RestAuthCommon.error.RestAuthSetupException

Thrown when service authentication failed.

On a protocol level, this represents HTTP status code 401.

exception RestAuthCommon.error.UnmarshalError[source]

Bases: RestAuthCommon.error.RestAuthImplementationException

Thrown if data can’t be unmarshalled.

exception RestAuthCommon.error.UnsupportedMediaType[source]

Bases: RestAuthCommon.error.ContentTypeException

The RestAuth service does not support the media type used by this client implementation.

On a protocol level, this represents HTTP status code 415.

Example

Here is a detailed example showing the different granularity-levels you may use:

from RestAuthCommon import error

try:
    # some code related to RestAuth:
    pass

# catch some general types of errors:
except error.RestAuthRuntimeException:
    print( "The authentication service suffers from internal problems." )
except error.RestAuthSetupException:
    print( "Configuration error." )

# do a more detailed report on data the user entered:
except error.ResourceNotFound:
    print( "The resource addressed wasn't found" )
except error.ResourceConflict:
    print( "Tried to create a resource that already exists" )

# make sure that no RestAuthException propagates:
except error.RestAuthException:
    print( "uncaught RestAuthException." )

Table Of Contents

Previous topic

Resource validation

This Page