Skip to content

Instantly share code, notes, and snippets.

@momolog
Last active December 23, 2015 20:29
Show Gist options
  • Select an option

  • Save momolog/6689856 to your computer and use it in GitHub Desktop.

Select an option

Save momolog/6689856 to your computer and use it in GitHub Desktop.
400 vs 500
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.
def do_something
if exp = params[:expected]
some_function
end
end
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