Skip to content

nginx and haproxy should respect Accept headers when responding with error templates #8179

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

Closed
dianabarsan opened this issue Apr 14, 2023 · 4 comments · Fixed by #8446
Closed
Assignees
Labels
Type: Improvement Make something better
Milestone

Comments

@dianabarsan
Copy link
Member

dianabarsan commented Apr 14, 2023

What feature do you want to improve?
Both nginx and haproxy use the default error templates for 4xx and 5xx responses. These templates are html.
Respecting the Accept header would standardize the behavior of the CHT, and this is important since we expect third party software to call CHT APIs.

To reproduce:

  • start CHT 4.x
  • stop your api container docker stop <api container name>
  • request a JSON response from API:
curl -k https://localhost -H 'Accept: application/json'
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.19.6</center>
</body>
</html>

If you are logged into webapp, you will see a JSON parse error spammed in the console:
image

Describe the improvement you'd like
We should change nginx and haproxy configs to respond with JSON when the Accept: application/json header is passed.

Describe alternatives you've considered
Leave it as it is.

Additional context
I had a script that passed the result of an API call to jq. Because the response was html, my jq call failed.
Similarly, we've seen reports of feedback docs being generated that feedback docs get generated in webapp when with Unexpected token < in JSON at position 0:

#6412
#7782

@dianabarsan dianabarsan added the Type: Improvement Make something better label Apr 14, 2023
@dianabarsan dianabarsan self-assigned this Apr 14, 2023
@garethbowen
Copy link
Contributor

Similarly, we've seen

The suspense is killing me!

@dianabarsan
Copy link
Member Author

The suspense is killing me!

Apologies. Resuscitation in progress.

@mrjones-plip
Copy link
Contributor

Also noting that the lack of a proper JSON and sending HTML instead affects more tickets than the two above. Spot checking one, I found: "This indicates that CouhchDb is down and Haproxy responds with html instead of JSON" #7759.

A fix to this will be a welcome addition!

@nydr
Copy link
Contributor

nydr commented Aug 17, 2023

We have suggested that HAProxy error pages to be JSON only since HAProxy is not externally available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Improvement Make something better
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants