Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vgsantoniazzi/rescuable-errors
rescuable-errors — Build API rescuable error classes.
https://github.com/vgsantoniazzi/rescuable-errors
api json-api rails ruby
Last synced: about 1 month ago
JSON representation
rescuable-errors — Build API rescuable error classes.
- Host: GitHub
- URL: https://github.com/vgsantoniazzi/rescuable-errors
- Owner: vgsantoniazzi
- Created: 2015-03-18T17:30:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-19T16:42:13.000Z (almost 9 years ago)
- Last Synced: 2024-09-30T09:41:28.598Z (about 2 months ago)
- Topics: api, json-api, rails, ruby
- Language: Ruby
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Welcome to Rescuable Errors
Rescue correctly your application errors.
## Getting Started
From command line:
```ruby
gem install rescuable_errors
```Gemfile:
```ruby
gem "rescuable_errors"
```## Usage
You can create errors into gem (if you use a fork) or in your application. For example, create app/errors/routing_error.rb in your application:
```ruby
module RescuableErrors
class RoutingError < RescuableErrors::ApplicationError
def initialize
@code = 404
@status = 404
@class = "RescuableErrors::RoutingError"
super I18n.t("errors.routing")
end
end
end```
and fail in controller with
```fail RescuableErrors::RoutingError.new```.
Now will automaticaly render a JSON response with status 404:
```ruby
"error": {
"code": 404,
"class": "RescuableErrors::RoutingError",
"message": "Routing not found."
}
```## Contributing
I :heart: Open source!
[Follow github guides for forking a project](https://guides.github.com/activities/forking/)
[Follow github guides for contributing open source](https://guides.github.com/activities/contributing-to-open-source/#contributing)
## Code Status
[![Build Status](https://travis-ci.org/vgsantoniazzi/rescuable-errors.svg?branch=master)](https://travis-ci.org/vgsantoniazzi/rescuable-errors)
## License
Gem is released under the [MIT license](http://opensource.org/licenses/MIT).