swagger-api / swagger-api/swagger-codegen

[JAVA] Unhelpful error message in case of empty response with jersey2 library

Open
#10,843 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When the api call fails with no content in the response, the error message of the exception is set to "error". Can it be set to the status line instead so that the stacktrace contains a more helpfull error message?

Swagger-codegen version

2.4.15 but same issue with latest version.

Swagger declaration file content or url

in modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache l719

       String message = "error";
       String respBody = null;
       if (response.hasEntity()) {
          try {
            respBody = String.valueOf(response.readEntity(String.class));
            message = respBody;
         } catch (RuntimeException e) {
           // e.printStackTrace();
         }
       }
Steps to reproduce

generate a client api with jersey2

Related issues/PRs

not reported afaik.

Suggest a fix/enhancement

provide the reason phrase instead of "error", for example :

"Error invoking API : " + response.getStatusInfo().getReasonPhrase();

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache around line 719 and generate a client API with the jersey2 library to reproduce the empty-response failure. Trace the exception message handling for responses without an entity; done means the stack trace uses the response status reason phrase instead of the literal "error".

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.