Skip to content

Commit 8f7fe7c

Browse files
Adds error handler instructions
1 parent deb51a1 commit 8f7fe7c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ The controller is built following SwitchDreams default way:
1717
Add this line to your application's Gemfile:
1818

1919
```ruby
20-
gem 'rest-api-generator'
20+
group :development do
21+
gem 'rest-api-generator'
22+
end
2123
```
2224

2325
And then execute:
@@ -30,13 +32,25 @@ Or install it yourself as:
3032

3133
## Requirements
3234

33-
You need to have installed in your application rspec and factory bot
35+
1. You need to have installed in your application rspec and factory bot
3436

3537
<ul>
3638
<li>Rspec: https://github.com/rspec/rspec-rails</li>
3739
<li>Factory bot: https://github.com/thoughtbot/factory_bot_rails</li>
3840
</ul>
3941

42+
2. Include in ApplicationController the error handler module:
43+
44+
```ruby
45+
class ApplicationController < ActionController::API
46+
include RestApiGenerator::ErrorHandler
47+
end
48+
```
49+
50+
This error handler will rescue from: `ActiveRecord::RecordNotFound`
51+
, `ActiveRecord::ActiveRecordError`, `ActiveRecord::RecordInvalid`, `ActiveModel::ValidationError`
52+
, `RestApiGenerator::CustomError`.
53+
4054
## Usage
4155

4256
### Generate Resource

0 commit comments

Comments
 (0)