Skip to content

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

Merged
zzak merged 1 commit into
sinatra:masterfrom
jkowens:fix-1058
May 9, 2016
Merged

Add error handling for requests with invalid params (Fixes #1058)#1070
zzak merged 1 commit into
sinatra:masterfrom
jkowens:fix-1058

Conversation

@jkowens

@jkowens jkowens commented Jan 20, 2016

Copy link
Copy Markdown
Member

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

jkowens commented Jan 22, 2016

Copy link
Copy Markdown
Member Author

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

zzak commented Jan 24, 2016

Copy link
Copy Markdown
Member

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

zzak commented Jan 24, 2016

Copy link
Copy Markdown
Member

/cc @sinatra/team-sinatra

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

zzak commented May 9, 2016

Copy link
Copy Markdown
Member

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
Comment thread lib/sinatra/base.rb

def params
super
rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e

Copy link
Copy Markdown
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
Copy Markdown
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