Sha256: b739c0ccf2c8e898514772b90da0a650009df96565e73883370548d179e073f9

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

# HTTP errors

Simple HTTP errors for your Ruby application. You can see [a complete list of http errors here](https://httpstatuses.com).

## Usage

Install it

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

Then in your application you can raise an HTTP error

```ruby
raise HttpError::Unauthorized
```

You can also set some detail information about the error

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

In your ApplicationController you can then handle the errors like this

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

Or you can implement your own handler for all `HttpError`s

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

Or for a specific, single error

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
http-errors-0.1.3 README.md
http-errors-0.1.1 README.md
http-errors-0.1.0 README.md