Skip to content

Commit e6ae7c7

Browse files
author
Sebastian Wilgosz
committed
Add error handling for all controller actions
1 parent 17aa7b4 commit e6ae7c7

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ gem 'puma', '~> 4.1'
2525
gem 'bootsnap', '>= 1.4.2', require: false
2626
gem 'jsom-pagination'
2727
gem 'jsonapi-serializer'
28+
gem 'jsonapi_errors_handler'
29+
2830
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
2931
# gem 'rack-cors'
3032

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ GEM
108108
rack
109109
jsonapi-serializer (2.1.0)
110110
activesupport (>= 4.2)
111+
jsonapi_errors_handler (0.4.0)
111112
listen (3.3.1)
112113
rb-fsevent (~> 0.10, >= 0.10.3)
113114
rb-inotify (~> 0.9, >= 0.9.10)
@@ -210,6 +211,7 @@ DEPENDENCIES
210211
factory_bot_rails
211212
jsom-pagination
212213
jsonapi-serializer
214+
jsonapi_errors_handler
213215
listen (~> 3.2)
214216
puma (~> 4.1)
215217
rails (~> 6.0.3, >= 6.0.3.4)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# frozen_string_literal: true
22

33
class ApplicationController < ActionController::API
4+
include JsonapiErrorsHandler
5+
6+
ErrorMapper.map_errors!(
7+
'ActiveRecord::RecordNotFound' =>
8+
'JsonapiErrorsHandler::Errors::NotFound'
9+
)
10+
rescue_from ::StandardError, with: lambda { |e| handle_error(e) }
411
end

0 commit comments

Comments
 (0)