Last active
December 23, 2015 20:29
-
-
Save momolog/6689856 to your computer and use it in GitHub Desktop.
400 vs 500
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Controller action expecting certain input. | |
| In case the input is not provided, the first version will fail with a 500 exception, | |
| a stack trace and an airbrake notification. | |
| But this is just invalid input and not an error for us to care about. | |
| Instead, like the second version, it should just return nothing and a status code | |
| 400 (Bad Request), effectively telling the user agent, that | |
| 1) This is your fault, your URL / input data is wrong | |
| 2) This request will always fail - do not retry! (as opposed to a 500, that may work later) | |
| Also, this is faster and does not spam our Airbrake. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def do_something | |
| if exp = params[:expected] | |
| some_function | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def do_something | |
| if exp = params[:expected] | |
| some_function | |
| else | |
| error_400 | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment