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

Rescue coerce errors and return an error hash #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

renatolond
Copy link

When using DateTime params (though possibly for other types too) the coerce step can fail because the date is invalid (it can be because it's a day that doesn't exist, such as 29/2 on non-leap years, or a string that cannot be parsed by DateTime).
The current behavior is to let this error bubble up and allow sinatra to return a 500. However, it should be caught by sinatra-browse and return a 400 for a graceful error.
This changes the behavior to catch exceptions around the coerce and return an error. I'm using a generic exception catch, but it could be more specialized to catch an ArgumentError, which is thrown by DateTime.parse.

@renatolond renatolond force-pushed the bugfix/invalid_date branch from 87102e8 to 000810b Compare July 30, 2020 07:57
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 this pull request may close these issues.

1 participant