Skip to main content
Skip table of contents

weblink - exception

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 WebInterfaceException is 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 WebInterfaceException can overwrite the error_translated property to add further information to the body

Function

Parameters

Return Value

Description

WebInterfaceException.__init__(self, status, error_text_constant, log_id=LogId.NO_LOG_ID)

status: The HTTP status code
error_text_constant: The text constant with the error message


log_id: A logging ID from the LogId enum

Instance

Initializes a new WebInterfaceException element.

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

JS
{
    "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"
        }
    }
}

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__(self, error_text_constant, log_id=LogId.NO_LOG_ID)

error_text_constant: ID of a text constant containing the error message


log_id: Optional ID to use when logging (currently unused)

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

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

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 ServiceImplementation.parse_json_text when the text contains invalid json. Contains details with further information.

SessionNotFoundWebInterfaceException

400

Raised when a server function raises a server.SessionNotFoundException

ModuleNotFoundWebInterfaceException

400

Raised when a server function raises a server.ModuleNotFoundWebInterfaceException

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 utilities.PojoSaveFailedException occurs.

EntityNotDeletedWithReasonException

500

Raised when a utilities.PojoDeleteFailedException occurs

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_translated property to define your own representation appropriate for your client

PY
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:

JS
{
    "error": "user-not-synced",
    "user": "R41"
}

This can then be used by the client to display an appropriate error message.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.