The form of the responses in case of an error, differs dependent of the thrown error.
In general the returned HTTP response codes are used as defined in https://datatracker.ietf.org/doc/html/rfc9110.
Though only the following are used:
Status Code | General Meaning | In translate5 |
---|---|---|
401 Unauthorized | Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. | No user is authenticated by the request. |
403 Forbidden | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. | See the additional error message in the result. This status code is returned when trying to access an API endpoint where the current user has no access rights. This status code is also used for other business logic based access rules (not only ACL based). Also when trying to do malicious requests the application might answer with an 403. |
404 Not Found | The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. | Either then whole API endpoint does not exist, or the concrete requested resource does not exist. For example when requesting a task: GET /editor/task/123 might return a 404 f the task was deleted. |
405 Method Not Allowed | The request method is known by the server but is not supported by the target resource. For example, an API may not allow calling DELETE to remove a resource. | Not all HTTP methods are implemented in all API endpoints. So if an invalid one was used 405 is returned. |
409 Conflict | This response is sent when a request conflicts with the current state of the server. | See the additional error message in the result. One prominent example: The data on the server has changed in the meantime and must be reloaded. |
422 Unprocessable Entity | The request was well-formed but was unable to be followed due to semantic errors. | See the additional error message in the result. The data itself produces an error, for example when creating a user where the login is already in use. |
500 Internal Server Error | The server has encountered a situation it does not know how to handle. | Multi-purpose error, see the additional error messages in the result. |
502 Bad Gateway | This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response. | Might be send if a underlying language resource (which are foreign services) can not be used. |
503 Service Unavailable | The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded. | The installation is in maintenance. |
According to the definition of HTTP response codes, the request delivers data which can not be processed or are invalid for the requested entity, or the creation / update of such an entity would lead to an conflict in the application. In both cases the result will look like the following example:
{ "errorCode": "E1094", "httpStatus": 422, "errorMessage": "User can not be saved: the chosen login does already exist.", "message": "Unprocessable Entity", "success": false, "errors": { "login": ["duplicateLogin"] }, "errorsTranslated": { "login": ["Dieser Anmeldename wird bereits verwendet."] } } |
Explanation of the single fields
Field | Example Value / Type | Description |
---|---|---|
errorCode | E1094 | This is the error code linking to a brief description / explanation of the problem in the translate5 event code list. |
httpStatus | 422 or 409 | The HTTP status of the answer, as returned also in the request headers. In the explained case 422 or 409. |
errorMessage | see above | A short explanation of the error in english. |
message | Unprocessable Entity | The textual representation of the HTTP status code, here "Unprocessable Entity" or "Conflict" |
success | true or false | simple flag representing the success state of the response, here of course false. |
errors | hashmap | A hashmap containing the input field containing the value which produces the problem, and an array of string identifier of the problem in english. |
errorsTranslated | hashmap | The same structure as the above errors field, with the difference that the error texts are translated in the language of the currently authenticated user. |