Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] [support needed] Error Response Body is empty #24

Open
hellboy81 opened this issue Jun 17, 2019 · 1 comment
Open

[Question] [support needed] Error Response Body is empty #24

hellboy81 opened this issue Jun 17, 2019 · 1 comment
Assignees
Labels
Waiting for feedback Waiting for feedback/some action to be able to move forward

Comments

@hellboy81
Copy link

I am trying to decode error response body but got always null:

code specific ErrorCodes error Exception classes are generated properly but with empty body:

image

Feign's OkHttp client is used.

Where is my bad?

Used versions:

  • Feign: 10.2.3
  • annotatiion-error-decoder: 1.2.0

P.S. Another developers from UA reported feign-error-decoder does not work properly.

See also my question in chat.

@saintf
Copy link
Collaborator

saintf commented Jul 22, 2019

@hellboy81 can you try:

There's one part in the exception generator that I'm not terribly proud of:

  private Object resolveBody(Response response) {
    if (bodyType instanceof Class<?> && ((Class<?>) bodyType).isInstance(response)) {
      return response;
    }
    try {
      return bodyDecoder.decode(response, bodyType);
    } catch (IOException e) {
      // How do we log this?
      return null;
    } catch (DecodeException e) {
      // How do we log this?
      return null;
    }
  }

you see that it basically tries its best to decode the body, but if it fails, it actually does so silently (yuck).

That said - Feign itself doesn't decide on a logger for you... which begs the question: how to best log?

I expect that ErrorResponse is likely being returned in a format you don't expect or that your POJO doesn't fit to. You can perhaps debug by having the constructor just take feign.Response and capture the body/decode it yourself just to see what is happening.

The other option is a little more intrusive (Support some form of logging - while still not trying to be opinionated - much like what Feign itself tries to do). If you have a proposal (maybe we include a Logger class/object that logs the error, and if available, the body or so) then I'll be happy to implement it (or even, if you are up for it, have you implement it and I'll review).

Thoughts?

@saintf saintf self-assigned this Jul 22, 2019
@saintf saintf added the Waiting for feedback Waiting for feedback/some action to be able to move forward label Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Waiting for feedback Waiting for feedback/some action to be able to move forward
Projects
None yet
Development

No branches or pull requests

2 participants