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

Error responses' Content-Type is always returned as text/plain for the client #826

Open
yamanaliesh92 opened this issue Dec 9, 2023 · 1 comment
Labels

Comments

@yamanaliesh92
Copy link

yamanaliesh92 commented Dec 9, 2023

Environment info:

  • KrakenD version:
KrakenD Version: 2.5.0
Go Version: 1.20.11
Glibc Version: MUSL-1.2.4_(alpine-3.18.4)
  • System info:
Docker version 23.0.1, build a5ee5b1
  • Hardware specs: 2 CPUs and 8GB of RAM allocated for the container
  • Backend technology: NodeJS
  • Additional environment information:

Describe what are you trying to do:

  • Trying to return error responses with header Content-Type: application/json without using output_encoding: 'no-op', backend error is returned with correct status and correct message but the response header Content-Type is always text/plain

Your configuration file:

{
  "$schema": "https://www.krakend.io/schema/krakend.json",
  "version": 3,
  "name": "KrakenD - API Gateway",
  "extra_config": { "router": { "return_error_msg": true } },
  "endpoints": [
    {
      "output_encoding": "json",
      "backend": [
        {
          "url_pattern": "/api",
          "method": "GET",
          "host": ["http://backend:3000"],
          "extra_config": { "backend/http": { "return_error_code": true } }
        }
      ],

      "endpoint": "/api",
      "method": "GET"
    }
  ]
}

Configuration check output:
Result of krakend check -dtc krakend.json --lint command

0 async agent(s):
Syntax OK!

Commands used:
How did you start the software?

krakend run -d -c krakend.json

Logs:

er/login"
newbackwithkrakend-gateway-1  | [00] Error #01: {"statusCode":400,"message":"email or password is not correct","error":"Bad Request"}

Additional comments:

  • I know using no-op would forward all headers of backend to the client including the Content-Type but i would like not to use no-op but still get my errors as json response
@yamanaliesh92 yamanaliesh92 changed the title Error responses' Content-Type is always returned text/plain for the client Error responses' Content-Type is always returned as text/plain for the client Dec 9, 2023
@andrewbrg
Copy link

andrewbrg commented Feb 7, 2024

Hi, yea we have the same issue.

Everything works fine but unless the endpoint is set as no-op the content-type header on the response when there is a non-2xx response status from the backend is completely ignored.

So Kraken, forwards the error message (JSON) from the backend to the client but then just serves it with a content-type of text/plain which causes issues with some clients.

I think return_error_code should either also forward the same header from the backend to the client or another parameter be made available on the config to achieve the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants