Skip to content

Commit dd070f4

Browse files
Merge branch 'master' into update-sentry-strategy-to-use-new-gem-version
2 parents aa855d9 + 1500495 commit dd070f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+240
-1467
lines changed

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
inherit_from: .rubocop_todo.yml
22

33
AllCops:
4-
TargetRubyVersion: 2.3
4+
TargetRubyVersion: 2.5
55
Exclude:
66
- 'vendor/**/*'
77
- 'rails_*/**/*'

.travis.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
---
2-
sudo: false
32
language: ruby
43
before_install:
54
- gem update --system
65
- gem install bundler
6+
install: bundle install --jobs=3 --retry=3
77
cache: bundler
88
branches:
99
only:
1010
- master
11-
matrix:
11+
jobs:
1212
include:
13-
- rvm: 2.3.8
14-
gemfile: ./rails_4_test_app/Gemfile
15-
script: cd rails_4_test_app && bundle exec rspec
16-
- rvm: 2.3.8
13+
- rvm: 2.5.1
1714
gemfile: ./rails_5_test_app/Gemfile
1815
script: cd rails_5_test_app && bundle exec rspec
1916
- rvm: 2.5.1
2017
gemfile: ./rails_6_test_app/Gemfile
2118
script: cd rails_6_test_app && bundle exec rspec
22-
- rvm: 2.3.8
19+
- rvm: 2.7.2
20+
gemfile: ./rails_6_test_app/Gemfile
21+
script: cd rails_6_test_app && bundle exec rspec
22+
- rvm: 3.0.0
23+
gemfile: ./rails_6_test_app/Gemfile
24+
script: cd rails_6_test_app && bundle exec rspec
25+
- rvm: 2.7.2
26+
gemfile: Gemfile
27+
script: bundle exec rubocop
28+
- rvm: 2.7.2
29+
gemfile: Gemfile
30+
script: bundle exec rspec
31+
- rvm: 3.0.0
2332
gemfile: Gemfile
2433
script: bundle exec rubocop
25-
- rvm: 2.3.8
34+
- rvm: 3.0.0
2635
gemfile: Gemfile
2736
script: bundle exec rspec

api_error_handler.gemspec

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
99
spec.version = ApiErrorHandler::VERSION
1010
spec.authors = ["James Stonehill"]
1111
spec.email = ["james.stonehill@gmail.com"]
12-
spec.required_ruby_version = "~> 2.3"
12+
spec.required_ruby_version = ">= 2.5"
1313

1414
spec.summary = <<~SUMMARY
1515
A gem that helps you easily handle exceptions in your Rails API and return
@@ -35,12 +35,13 @@ Gem::Specification.new do |spec|
3535
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
3636
spec.require_paths = ["lib"]
3737

38-
spec.add_dependency "activesupport", ">= 4.0"
39-
spec.add_dependency "actionpack", ">= 4.0"
38+
spec.add_dependency "activesupport", ">= 5.0"
39+
spec.add_dependency "actionpack", ">= 5.0"
4040
spec.add_dependency "rack", ">= 1.0"
4141

4242
spec.add_development_dependency "bundler", "~> 2.0"
43-
spec.add_development_dependency "rake", "~> 10.0"
44-
spec.add_development_dependency "rspec-rails", "~> 3.0"
45-
spec.add_development_dependency "rubocop", "~> 0.74.0"
43+
spec.add_development_dependency "rake", "~> 13.0"
44+
spec.add_development_dependency "rspec-rails", "~> 3.9"
45+
spec.add_development_dependency "rubocop", "~> 0.80.0"
46+
spec.add_development_dependency "pry-byebug"
4647
end

lib/api_error_handler.rb

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require_relative "./api_error_handler/action_controller"
55
require_relative "./api_error_handler/error_id_generator"
66
require_relative "./api_error_handler/error_reporter"
7-
Dir[File.join(__dir__, "api_error_handler", "serializers", "*.rb")].each do |file|
7+
Dir[File.join(__dir__, "api_error_handler", "serializers", "*.rb")].sort.each do |file|
88
require file
99
end
1010

@@ -33,25 +33,23 @@ def handle_api_errors(options = {})
3333
serializer_class = options[:serializer] || SERIALIZERS_BY_FORMAT.fetch(format)
3434
content_type = options[:content_type] || CONTENT_TYPE_BY_FORMAT[format]
3535
rescue_from StandardError do |error|
36-
begin
37-
status = ActionDispatch::ExceptionWrapper.rescue_responses[error.class.to_s]
38-
39-
error_id = ErrorIdGenerator.run(options[:error_id])
40-
error_reporter.report(error, error_id: error_id)
41-
42-
serializer = serializer_class.new(error, status)
43-
response_body = serializer.serialize(
44-
serializer_options.merge(error_id: error_id)
45-
)
46-
47-
render(
48-
serializer.render_format => response_body,
49-
content_type: content_type,
50-
status: status
51-
)
52-
rescue
53-
raise error
54-
end
36+
status = ActionDispatch::ExceptionWrapper.rescue_responses[error.class.to_s]
37+
38+
error_id = ErrorIdGenerator.run(options[:error_id])
39+
error_reporter.report(error, error_id: error_id)
40+
41+
serializer = serializer_class.new(error, status)
42+
response_body = serializer.serialize(
43+
serializer_options.merge(error_id: error_id)
44+
)
45+
46+
render(
47+
serializer.render_format => response_body,
48+
content_type: content_type,
49+
status: status
50+
)
51+
rescue
52+
raise error
5553
end
5654
end
5755
end

lib/api_error_handler/action_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
require "action_controller"
55

66
ActiveSupport.on_load :action_controller do
7-
::ActionController::Base.send :extend, ApiErrorHandler
8-
::ActionController::API.send :extend, ApiErrorHandler
7+
::ActionController::Base.extend ApiErrorHandler
8+
::ActionController::API.extend ApiErrorHandler
99
end

rails_4_test_app/.rspec

Lines changed: 0 additions & 1 deletion
This file was deleted.

rails_4_test_app/Gemfile

Lines changed: 0 additions & 52 deletions
This file was deleted.

rails_4_test_app/Gemfile.lock

Lines changed: 0 additions & 188 deletions
This file was deleted.

rails_4_test_app/Rakefile

Lines changed: 0 additions & 6 deletions
This file was deleted.

rails_4_test_app/app/assets/config/manifest.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)