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::UnauthorizedYou 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
endOr you can implement your own handler for all HttpErrors
class ApplicationController < ActionController::Base
  rescue_from HttpError::Error do |error|
    # Handle the error here
  end
endOr 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