Skip to main content
Skip table of contents

weblink - exception

Die nachfolgenden Inhalte sind nur in englischer Sprache verfügbar.

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
FunctionParametersReturn ValueDescription
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

InstanceInitializes a new WebInterfaceException element. 
PropertyGetterSetterDescription
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

Example output when a error occurs

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


FunctionParametersReturn 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 ClassHTTP Status CodeStatus Code Name

LockedException

423LOCKED

NotAcceptableException

406NOT ACCEPTABLE

BadRequestException

400BAD REQUEST

NotFoundException

404NOT FOUND

InternalServerErrorException

500INTERNAL SERVER ERROR

ExpectationFailedException

417EXPECTATION FAILED

ConflictException

409CONFLICT

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 ClassHTTP Status CodeDescription
EntityNotFoundException404The current action was cancelled because the specified object doesn't exist
ProjectLockedException423The current action was cancelled because the project is locked
TaskLockedException423The current action was cancelled because the task is locked
ProjectFinishedException423The current action was cancelled because the project is finished
TaskFinishedException423The current action was cancelled because the task is finished
ResourceAssignmentFinishedException423The current action was cancelled because the resource assignment is finished
InterfaceLockException423The current action was cancelled because the booking is already linked to an external system
BookingCancelledException423The current action was cancelled because the booking was cancelled
ReleasedException423The current action was cancelled because the booking was released
DeadlineException423The current action was cancelled because the booking date is before the deadline
ProjectNotActiveException423The current action was cancelled because the project is inactive
MaxHoursReachedException406The curent action was cancelled because the resource has reached their maximum allowed booking time
FutureReportingException406The current action was cancelled because the project does not allow booking into the future
OutsideReportingPeriodException406The current action was cancelled because the booking is outside the booking window
NegativeLoadException400The 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 ClassHTTP Status CodeDescription
EntityAttributesNotSetException400Raised 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. 
TransformationException400Raised when a error occurs while applying the Transformers on the data. Contains details with further information.
MandatoryAttributesMissingException400Raised when a mandatory attribute is missing in a request to the default PUT/POST interface. Contains details with further information.
SuperfluousAttributesInRequestException400Raised when superfluous attributes are present in a request to the default PUT/POST interface. Contains details with further information.
InvalidJsonException400Raised by ServiceImplementation.parse_json_text when the text contains invalid json. Contains details with further information.
SessionNotFoundWebInterfaceException400Raised when a server function raises a server.SessionNotFoundException
ModuleNotFoundWebInterfaceException400Raised when a server function raises a server.ModuleNotFoundWebInterfaceException
UnhandledException500Raised for all unhandled exceptions. Contains details with the exception. If the web interface is set to debug logging the details also contain the traceback.
EntityNotSavedWithReasonException500Raised when a utilities.PojoSaveFailedException occurs. 
EntityNotDeletedWithReasonException500Raised 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


Custom exception example

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:

Example json body

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.