Base class
WebInterfaceException
The WebInterfaceException is the base class for exceptions in web interfaces
-
It requires a status code to set on the response when the error is encountered and a text constant id for a error message to display
-
When a
WebInterfaceExceptionis handled by the web interface framework the status code is set and a body is generated consisting of a json dictionary with an error message in all available languages and optional further details-
This can then be used by an external client to display an error to the user
-
-
Subclasses of
WebInterfaceExceptioncan overwrite theerror_translatedproperty to add further information to the body
Methods
|
Function |
Parameters |
Return Value |
Description |
|---|---|---|---|
|
WebInterfaceException.__init__( |
status: The HTTP status code
|
Instance |
Initializes a new WebInterfaceException element. |
Properties
|
Property |
Getter |
Setter |
Description |
|---|---|---|---|
|
WebInterfaceException.error_translated |
Implements the python object that should be used as a body in the response.
Returns the text constant with the error message as a dictionary of language: error text by default |
{
"DE": "Bei der Transformation sind Fehler aufgetreten.",
"PT": "Ocorreram erros na transformação.",
"EN": "Errors occurred during transformation.",
"FR": "Des erreurs se sont produites pendant la transformation.",
"details": {
"date": {
"error": "java.text.ParseException: Unparseable date: \"19.09.1991\""
},
"taskUUID": {
"error": "No task exists with uuid \"bad-uuid\""
},
"userID": {
"error": "No user with external id \"bad-user\" exists"
}
}
}
Base classes for specific HTTP status code
These classes all set a specific status code on the response when they are raised during the execution of a web interface.
-
They all share the same
__init__method and require a text constant to be initialized
|
Function |
Parameters |
Return Value |
|---|---|---|
|
__init__( |
error_text_constant: ID of a text constant containing the error message
|
Instance |
|
Exception Class |
HTTP Status Code |
Status Code Name |
|---|---|---|
|
LockedException |
423 |
LOCKED |
|
NotAcceptableException |
406 |
NOT ACCEPTABLE |
|
BadRequestException |
400 |
BAD REQUEST |
|
NotFoundException |
404 |
NOT FOUND |
|
InternalServerErrorException |
500 |
INTERNAL SERVER ERROR |
|
ExpectationFailedException |
417 |
EXPECTATION FAILED |
|
ConflictException |
409 |
CONFLICT |
Exception instances for different business usecases
This is a list of exception instances already defined for several typical web interface use cases.
-
When they are handled by the web framework, the status code and body is set automatically
|
Exception Class |
HTTP Status Code |
Description |
|---|---|---|
|
EntityNotFoundException |
404 |
The current action was cancelled because the specified object doesn't exist |
|
ProjectLockedException |
423 |
The current action was cancelled because the project is locked |
|
TaskLockedException |
423 |
The current action was cancelled because the task is locked |
|
ProjectFinishedException |
423 |
The current action was cancelled because the project is finished |
|
TaskFinishedException |
423 |
The current action was cancelled because the task is finished |
|
ResourceAssignmentFinishedException |
423 |
The current action was cancelled because the resource assignment is finished |
|
InterfaceLockException |
423 |
The current action was cancelled because the booking is already linked to an external system |
|
BookingCancelledException |
423 |
The current action was cancelled because the booking was cancelled |
|
ReleasedException |
423 |
The current action was cancelled because the booking was released |
|
DeadlineException |
423 |
The current action was cancelled because the booking date is before the deadline |
|
ProjectNotActiveException |
423 |
The current action was cancelled because the project is inactive |
|
MaxHoursReachedException |
406 |
The curent action was cancelled because the resource has reached their maximum allowed booking time |
|
FutureReportingException |
406 |
The current action was cancelled because the project does not allow booking into the future |
|
OutsideReportingPeriodException |
406 |
The current action was cancelled because the booking is outside the booking window |
|
NegativeLoadException |
400 |
The current action was cancelled because negative loads are not permitted |
Framework Exceptions
These exceptions are raised by the DefaultServiceImplementation and from inside the web interface framework in general
|
Exception Class |
HTTP Status Code |
Description |
|---|---|---|
|
EntityAttributesNotSetException |
400 |
Raised when an error occurs while applying the attributes from the web to a POJO or when the client gives us data for a read only attribute. Contains details with further information. |
|
TransformationException |
400 |
Raised when a error occurs while applying the Transformers on the data. Contains details with further information. |
|
MandatoryAttributesMissingException |
400 |
Raised when a mandatory attribute is missing in a request to the default PUT/POST interface. Contains details with further information. |
|
SuperfluousAttributesInRequestException |
400 |
Raised when superfluous attributes are present in a request to the default PUT/POST interface. Contains details with further information. |
|
InvalidJsonException |
400 |
Raised by |
|
SessionNotFoundWebInterfaceException |
400 |
Raised when a server function raises a |
|
ModuleNotFoundWebInterfaceException |
400 |
Raised when a server function raises a |
|
UnhandledException |
500 |
Raised for all unhandled exceptions. Contains details with the exception. If the web interface is set to debug logging the details also contain the traceback. |
|
EntityNotSavedWithReasonException |
500 |
Raised when a |
|
EntityNotDeletedWithReasonException |
500 |
Raised when a |
Defining custom exceptions
With a custom exception derived from one of the classes above you can easily raise errors from your implementation and have the web framework handle the formatting.
-
You can overwrite the
errors_translatedproperty to define your own representation appropriate for your client
from customizing.weblink import BadRequestException
class UserNotSyncedException(BadRequestException):
def __init__(self, user):
self._user = user
@property
def error_translated(self):
obj = {'error': 'user-not-synced',
'user': self._user}
When this exception is raised in an interface, for example during the post method the response will automatically have status code 400 and a body like this:
{
"error": "user-not-synced",
"user": "R41"
}
This can then be used by the client to display an appropriate error message.