question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use Zalando Problem for all json responses

See original GitHub issue
Overview 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:closed
  • Created 6 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
cbornetcommented, Sep 25, 2017

I’m precisely working on this 😄 @henri-tremblay

0reactions
cbornetcommented, Oct 5, 2017

Fixed by #6459 and #6411

Read more comments on GitHub >

github_iconTop Results From Across the Web

zalando/problem: A Java library that implements ... - GitHub
Problem is a library that implements application/problem+json . It comes with an extensible set of interfaces/implementations as well as convenient ...
Read more >
A Guide to the Problem Spring Web Library - Baeldung
In this tutorial, we're going to explore how to produce application/problem+json responses using the Problem Spring Web library.
Read more >
Zalando RESTful API and Event Guidelines
Zalando's software architecture centers around decoupled microservices that provide functionality via RESTful APIs with a JSON payload.
Read more >
org.zalando.problem.Problem Java Examples
This page shows Java code examples of org.zalando.problem.Problem. ... The following examples show how to use org.zalando.problem.Problem.
Read more >
Best Practices - API Principles
Specify Success and Error Responses; Use Most Specific HTTP Status Codes ... We apply the RESTful web service principles to all kind of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found