Skip to content

Commit

Permalink
Merge pull request #18 from hfcorreia/bump-versions
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesstonehill authored Jul 5, 2021
2 parents 71446e1 + 3f8678d commit 1500495
Show file tree
Hide file tree
Showing 74 changed files with 240 additions and 1,467 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.5
Exclude:
- 'vendor/**/*'
- 'rails_*/**/*'
Expand Down
25 changes: 17 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
---
sudo: false
language: ruby
before_install:
- gem update --system
- gem install bundler
install: bundle install --jobs=3 --retry=3
cache: bundler
branches:
only:
- master
matrix:
jobs:
include:
- rvm: 2.3.8
gemfile: ./rails_4_test_app/Gemfile
script: cd rails_4_test_app && bundle exec rspec
- rvm: 2.3.8
- rvm: 2.5.1
gemfile: ./rails_5_test_app/Gemfile
script: cd rails_5_test_app && bundle exec rspec
- rvm: 2.5.1
gemfile: ./rails_6_test_app/Gemfile
script: cd rails_6_test_app && bundle exec rspec
- rvm: 2.3.8
- rvm: 2.7.2
gemfile: ./rails_6_test_app/Gemfile
script: cd rails_6_test_app && bundle exec rspec
- rvm: 3.0.0
gemfile: ./rails_6_test_app/Gemfile
script: cd rails_6_test_app && bundle exec rspec
- rvm: 2.7.2
gemfile: Gemfile
script: bundle exec rubocop
- rvm: 2.7.2
gemfile: Gemfile
script: bundle exec rspec
- rvm: 3.0.0
gemfile: Gemfile
script: bundle exec rubocop
- rvm: 2.3.8
- rvm: 3.0.0
gemfile: Gemfile
script: bundle exec rspec
13 changes: 7 additions & 6 deletions api_error_handler.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
spec.version = ApiErrorHandler::VERSION
spec.authors = ["James Stonehill"]
spec.email = ["[email protected]"]
spec.required_ruby_version = "~> 2.3"
spec.required_ruby_version = ">= 2.5"

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

spec.add_dependency "activesupport", ">= 4.0"
spec.add_dependency "actionpack", ">= 4.0"
spec.add_dependency "activesupport", ">= 5.0"
spec.add_dependency "actionpack", ">= 5.0"
spec.add_dependency "rack", ">= 1.0"

spec.add_development_dependency "bundler", "~> 2.0"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec-rails", "~> 3.0"
spec.add_development_dependency "rubocop", "~> 0.74.0"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec-rails", "~> 3.9"
spec.add_development_dependency "rubocop", "~> 0.80.0"
spec.add_development_dependency "pry-byebug"
end
38 changes: 18 additions & 20 deletions lib/api_error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require_relative "./api_error_handler/action_controller"
require_relative "./api_error_handler/error_id_generator"
require_relative "./api_error_handler/error_reporter"
Dir[File.join(__dir__, "api_error_handler", "serializers", "*.rb")].each do |file|
Dir[File.join(__dir__, "api_error_handler", "serializers", "*.rb")].sort.each do |file|
require file
end

Expand Down Expand Up @@ -33,25 +33,23 @@ def handle_api_errors(options = {})
serializer_class = options[:serializer] || SERIALIZERS_BY_FORMAT.fetch(format)
content_type = options[:content_type] || CONTENT_TYPE_BY_FORMAT[format]
rescue_from StandardError do |error|
begin
status = ActionDispatch::ExceptionWrapper.rescue_responses[error.class.to_s]

error_id = ErrorIdGenerator.run(options[:error_id])
error_reporter.report(error, error_id: error_id)

serializer = serializer_class.new(error, status)
response_body = serializer.serialize(
serializer_options.merge(error_id: error_id)
)

render(
serializer.render_format => response_body,
content_type: content_type,
status: status
)
rescue
raise error
end
status = ActionDispatch::ExceptionWrapper.rescue_responses[error.class.to_s]

error_id = ErrorIdGenerator.run(options[:error_id])
error_reporter.report(error, error_id: error_id)

serializer = serializer_class.new(error, status)
response_body = serializer.serialize(
serializer_options.merge(error_id: error_id)
)

render(
serializer.render_format => response_body,
content_type: content_type,
status: status
)
rescue
raise error
end
end
end
4 changes: 2 additions & 2 deletions lib/api_error_handler/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
require "action_controller"

ActiveSupport.on_load :action_controller do
::ActionController::Base.send :extend, ApiErrorHandler
::ActionController::API.send :extend, ApiErrorHandler
::ActionController::Base.extend ApiErrorHandler
::ActionController::API.extend ApiErrorHandler
end
1 change: 0 additions & 1 deletion rails_4_test_app/.rspec

This file was deleted.

52 changes: 0 additions & 52 deletions rails_4_test_app/Gemfile

This file was deleted.

188 changes: 0 additions & 188 deletions rails_4_test_app/Gemfile.lock

This file was deleted.

6 changes: 0 additions & 6 deletions rails_4_test_app/Rakefile

This file was deleted.

2 changes: 0 additions & 2 deletions rails_4_test_app/app/assets/config/manifest.js

This file was deleted.

Empty file.
Loading

0 comments on commit 1500495

Please sign in to comment.