No commit activity in last 3 years
No release in over 3 years
"sinatra-errorcodes is the sinatra extension that contains a pack of HTTP error status code and message"
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 10.0
~> 3.0

Runtime

~> 2.0.2
 Project Readme

Sinatra::Errorcodes

Gem Version CircleCI standard-readme compliant

Gem of HTTP error status code class pack

Table of Contents

Installation

Add this line to your application's Gemfile:

gem 'sinatra-errorcodes'

Or install it yourself as:

$ gem install sinatra-errorcodes

Usage

To use this gem, at first, you need to register Sinatra::Errorcodes in your configure block and call handle_errorstatus which wraps Sinatra's error handling block.

class AppController < Sinatra::Base
  configure do
    register Sinatra::Errorcodes
  end
end

Now you can use a set of HTTPError class which contains HTTP status code and its message.

halt_with_errors

You can use halt_with_errors option which is false by default.

class AppController < Sinatra::Base
  configure do
    register Sinatra::Errorcodes
    
    set :halt_with_errors, true
  end
end

With the option, errors thrown with HTTPError class are caught automatically and call halt.

...

  get '/badrequest'
    raise HTTPError::BadRequest
  end
  
  get '/error'
    raise HTTPError::InternalServerError
  end
  
  # You can also raise an exception with your own custom message.
  get '/custom'
    raise HTTPError::InternalServerError, 'Custom error message'
  end
  
...

Example

Install gems

$ bundle install

and run it

$ cd example
$ bundle exec rackup -p 3000

Test

$ bundle exec rake spec

Contribute

PRs accepted.

License

The gem is available as open source under the terms of the MIT License.