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

Unexpected Content-Type when setting return_error_code and return_error_msg #707

Closed
bfoosness opened this issue Feb 2, 2024 · 6 comments
Labels

Comments

@bfoosness
Copy link

Describe the bug
I've combed through the documentation looking for an explanation or misconfiguration on my part, so my apologies if this is expected. I'm trying to implement this strategy:

https://www.krakend.io/docs/backends/detailed-errors/#return-the-http-status-code-of-a-single-backend

Return the HTTP status code and error body of a single backend. No obfuscation at all. Forwards the error body and the status code of a single backend. Use return_error_code and return_error_msg together.

I have added the following configuration to my endpoint's backend, and I have added "return_error_msg": true to my router configuration.

"extra_config": {
    "backend/http": {
        "return_error_code": true
    }
}

I do indeed see the HTTP status code and error body of my backend returned after adding this configuration. However, the Content-Type of the response is text/plain for any non-2xx responses instead of application/json like I would expect. For 2xx responses, Content-Type is application/json as expected.

My understanding is that the default output_encoding is json, and I do not override that anywhere. I've tried explicitly setting the output_encoding to json on the endpoint and setting the encoding to json in the endpoint's backend configuration, but so far I've had no luck in getting the content-type to return as application/json.

Is this expected or a bug? Is there any way to force non-2xx responses to use application/json when using return_error_code and return_error_msg?

Expected behavior
Both 2xx and non-2xx responses use Content-Type: application/json when setting "return_error_code": true and "return_error_msg": true.

Thank you for reviewing!

@taik0
Copy link
Contributor

taik0 commented Feb 16, 2024

Hi @bfoosness
This is being adressed in #708 . It will try to capture the Content-Type of the error.

@bfoosness
Copy link
Author

Amazing! Thank you, @taik0

@taik0 taik0 closed this as completed Mar 4, 2024
@bfoosness
Copy link
Author

Thank you for closing, @taik0. I haven't been able to verify the fix yet, but I'm hopeful this will address it. Do you know when the next release will be for https://hub.docker.com/r/devopsfaith/krakend/tags?

@alombarte
Copy link
Member

alombarte commented Mar 12, 2024

Hi @bfoosness,
This was released yesterday
Thanks for reporting

@bfoosness
Copy link
Author

Many thanks, @alombarte! I confirmed that this fix is working as intended.

Copy link

This issue was marked as resolved a long time ago and now has been automatically locked as there has not been any recent activity after it. You can still open a new issue and reference this link.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants