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

Returns 500 Internal Server Error on bad request #225

Closed
nguiard opened this issue Sep 28, 2024 · 0 comments · Fixed by #228
Closed

Returns 500 Internal Server Error on bad request #225

nguiard opened this issue Sep 28, 2024 · 0 comments · Fixed by #228
Assignees

Comments

@nguiard
Copy link

nguiard commented Sep 28, 2024

Hello,

I was trying your nice extractors, and I came about something surprising. Basic code:

export start1

using Oxygen

struct Form1
    name::String
end

function hdl_form1(req, data::Form{Form1})
    display(data.payload)
end

function start1()
    @post "/form1" hdl_form1
    serve()
end

Problem 1 (500 instead of 400)

Then, doing curl -X POST http://localhost:8080/form1 --data 'name=John' works fine (as expected).
But doing curl -X POST http://localhost:8080/form1 --data '' or curl -X POST http://localhost:8080/form1 --data 'toto=lala' responds with a 500: Internal Server Error, and the server prints an error.

These last requests are bad requests, and I suppose the server should treat them as such, appropriately return a 400: Bad Request to indicate to the client that the problem lies with him (malformed request, not a server problem), and not print errors (as these are not server errors). Or am I missing a way to properly handle this?

Problem 2 (extraneous data is ignored)

If you do curl -X POST http://localhost:8080/form1 --data 'name=Jean&x=3', the server accepts the data silently. While this behavior is sometimes desirable, it would be nice to be able to disable it and be able to also return a 400: Bad Request to the client in case of extraneous data. That would make debugging easier in many cases. Could there be a way to do it?

I would even argue it should be the default, but I guess that really depends on taste and goals.

@ndortega ndortega self-assigned this Oct 15, 2024
@ndortega ndortega linked a pull request Oct 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants