0.0
No commit activity in last 3 years
No release in over 3 years
Easy way to raise HTTP errors from your ruby application
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 10.0
~> 3.0

Runtime

 Project Readme

HTTP errors

Simple HTTP errors for your Ruby application. You can see a complete list of http errors here.

Usage

Install it

gem 'http-errors', require: 'http_error'

Then in your application you can raise an HTTP error

raise HttpError::Unauthorized

You can also set some detail information about the error

raise HttpError::Unauthorized, 'Invalid email or password'

In your ApplicationController you can then handle the errors like this

class ApplicationController < ActionController::Base
  include HttpError::Response
end

Or you can implement your own handler for all HttpErrors

class ApplicationController < ActionController::Base
  rescue_from HttpError::Error do |error|
    # Handle the error here
  end
end

Or for a specific, single error

class ApplicationController < ActionController::Base
  rescue_from HttpError::Teapot do |error|
    render json: { error: 'This is silly' }, status: 418
  end
end