Use Zalando Problem for all json responses
See original GitHub issueOverview of the issue
I think it could be useful to choose a unique json format to handle API errors.
The exception handling uses zalando problem through the ExceptionTranslator.
{
"type": "http://www.jhipster.tech/problem/contraint-violation",
"title": "Method argument not valid",
"status": 400,
"message": "error.validation",
"fieldErrors": [
{
"objectName": "todoListDTO",
"field": "name",
"message": "NotNull"
}
]
}
The EntityResource controllers return the error details in the HTTP headers, e.g.
x-jtodoapp-error →A new todoList cannot already have an ID
the AccountResource has its own logic, for example for wrong credentials
{
"AuthenticationException": "Bad credentials"
}
the Http401UnauthorizedEntryPoint returns the spring json default format
{
"timestamp": "2017-09-25T10:06:18.672+0000",
"status": 401,
"error": "Unauthorized",
"message": "Access Denied",
"path": "/api/todo-items"
}
I’m wondering if there is some reason why the exception translator and zalando problem (or the ErrorVM before it) aren’t use globally.
Motivation for or Use Case
Most of the APIs we generate with jhipster are exposed to external applications (both web and mobile). We noticed that even documenting these different behaviours it is still quite confusing for those who have to interact with the APIs.
Suggest a Fix
Exceptions could be used in all the generated controllers and in the accountResource, so that all the errors are handled by the ExceptionTranslator. The Http401UnauthorizedEntryPoint could then use the object mapper to serialize a Problem object in the response body.
JHipster Version(s)
4.8.2
- Checking this box is mandatory (this is just to show you read everything)
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (11 by maintainers)
I’m precisely working on this 😄 @henri-tremblay
Fixed by #6459 and #6411