I have a custom error message for 400 status code:
get '/do' do
raise ParamXMissingError unless params['x']
end
error ParamXMissingError do
haml :custom_error_page
end
I want ParamXMissingError to be 400, but when I run the above code, and check through Firefox Network tools, it seems Sinatra is actually returning 500, not 400. How do I make it display the custom_error_page.haml
and return 400?
Preferably, it'd be nice to have the status code and the page handled from inside the error block, not something that I would sprinkle around when raising ParamXMissingError
. For example, this would be repetitive and not a good solution:halt 400, haml(:custom_error_page)
Doh. All I need is to set status 400
:
error ParamXMissingError do
status 400
haml :custom_error_page
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With