Skip to content

YouWeApS/arctic-gems-http_errors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Easy HTTP errors for your ruby application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published