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

Add error handling for requests with invalid params (Fixes #1058) #1070

Merged
merged 1 commit into from
May 9, 2016

Conversation

jkowens
Copy link
Member

@jkowens jkowens commented Jan 20, 2016

Requests that raise errors when parsing query parameters will now respond with a 400 status instead of 500 as suggested by the Rack docs. Fixes #1058. See #1058 for steps to reproduce.

Exceptions caused by parsing bad parameters were raised outside of the dispatch! method so the default exception handler was not invoked. That is why these exceptions bubbled up to the app server and exception messages were being displayed in the browser.

@jkowens jkowens force-pushed the fix-1058 branch 9 times, most recently from a297e70 to 45044e8 Compare January 21, 2016 01:37
@jkowens jkowens changed the title Add bad_request error handler Add bad_request error handler (Fixes #1058) Jan 21, 2016
@jkowens jkowens force-pushed the fix-1058 branch 3 times, most recently from cab3170 to b51de25 Compare January 22, 2016 05:32
@jkowens jkowens changed the title Add bad_request error handler (Fixes #1058) Add error handling for requests with invalid params (Fixes #1058) Jan 22, 2016
@jkowens jkowens force-pushed the fix-1058 branch 3 times, most recently from 3b13a0a to 77ada0c Compare January 22, 2016 06:27
@jkowens
Copy link
Member Author

jkowens commented Jan 22, 2016

I've iterated on this several times, but I think I've finally got it figured out. If someone could review this and provide comments/suggestions that would be awesome!

@zzak
Copy link
Member

zzak commented Jan 24, 2016

Yeesh, I'm afraid this issue is too ambitious to try to make into the next stable release.

I'm worried that my eyes are too weary to make this decision alone. Let's wait for more feedback.

@zzak zzak added the feedback label Jan 24, 2016
@zzak
Copy link
Member

zzak commented Jan 24, 2016

/cc @sinatra/team-sinatra

Requests that raise an error when parameters are parsed will
now respond with a 400 status instead of 500.
@zzak
Copy link
Member

zzak commented May 9, 2016

After looking into this I think it's ok to merge for the next major release.

@jkowens Thank you!

@zzak zzak merged commit 939ce04 into sinatra:master May 9, 2016
@jkowens jkowens deleted the fix-1058 branch May 9, 2016 14:14
@@ -73,6 +73,12 @@ def unlink?
request_method == "UNLINK"
end

def params
super
rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zzak If there is any interest in backporting this fix to stable this would have to be changed to rescuing TypeError and ArgumentError.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, since I consider this a behavior change and added functionality

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

Successfully merging this pull request may close these issues.

2 participants