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

404 errors with APIv4 has incorrect content-type header #20878

Closed
NicolasCARPi opened this issue Aug 25, 2022 · 7 comments · Fixed by #21047
Closed

404 errors with APIv4 has incorrect content-type header #20878

NicolasCARPi opened this issue Aug 25, 2022 · 7 comments · Fixed by #21047
Assignees
Labels
Difficulty/1:Easy Easy ticket Good First Issue Suitable for first-time contributors Help Wanted Community help wanted Tech/Go Server

Comments

@NicolasCARPi
Copy link

Version used: 6.6.2 in Docker.

Summary

The 404 response sent by apiv4 have a content-type header of text/plain; charset=utf-8 instead of application/json. But the documentation states that all responses are application/json.

Steps to reproduce

Access an invalid api endpoint or none at all:

Expected behavior

The response header content-type should be application/json and the response should be displayed in the browser as json (firefox pretty prints json responses).

2022-08-25-030859_580x156_scrot

Observed behavior (that appears unintentional)

The error message is displayed as text instead of being interpreted as JSON.
2022-08-25-030755_524x80_scrot

2022-08-25-031549_240x154_scrot

Possible fixes

Ensure 404 handler sends correct headers, unless of course this is intentional design, in which case I would be interested in knowing the reason ;)

Thanks for the great software everyone and have a terrific day! 🚀

@agnivade
Copy link
Member

agnivade commented Aug 25, 2022

Great catch @NicolasCARPi !

This is happening because the 404 handler is not wrapped in web.Handler which adds the application/json header. The line is here: https://github.com/mattermost/mattermost-server/blob/6adbcc5d05b9296135f685a08075e278a377603e/api4/api.go#L315.

If you are feeling up to it, please do send a PR, and we'll be happy to take a look.

@NicolasCARPi
Copy link
Author

Sorry I am not familiar enough with the codebase to try and fix that by myself :/

@amyblais
Copy link
Member

@amyblais amyblais added the Bug Report/Open Bug report/issue label Aug 25, 2022
@agnivade
Copy link
Member

@amyblais - Let's create this issue itself as an HW ticket. I will close the JIRA issue.

@agnivade agnivade added Difficulty/1:Easy Easy ticket Tech/Go Server Good First Issue Suitable for first-time contributors Help Wanted Community help wanted labels Aug 25, 2022
@amyblais amyblais removed the Bug Report/Open Bug report/issue label Aug 25, 2022
@clementbowe14
Copy link

Can I take on this issue?

@agnivade
Copy link
Member

Go ahead @clementbowe14 !

@safakkizkin
Copy link
Contributor

safakkizkin commented Sep 19, 2022

@agnivade
It's been a long time no activity here, if it's ok I can do it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty/1:Easy Easy ticket Good First Issue Suitable for first-time contributors Help Wanted Community help wanted Tech/Go Server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants