Sinatra Basics : Customizing Status Code and Error Message
To learn how to use halt method.
require 'sinatra' get '/' do halt 400, 'Validation failed' end
You can use the status method, but it does not allow providing a custom error message.
Run the application.
You see status code 400 in the server log and 'Validation failed' in the browser.
Change the status code to 500 and refresh the browser. You will now see the status code is 500.
In this article, you learned how to use halt method to customize status code and error message in a Sinatra application.
Ace the Technical Interview
- Easily find the gaps in your knowledge
- Get customized lessons based on where you are
- Take consistent action everyday
- Builtin accountability to keep you on track
- You will solve bigger problems over time
- Get the job of your dreams
Take the 30 Day Coding Skills Challenge
Gain confidence to attend the interview