api_error_handler 0.1.0.rc

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 136050d80b1f4f57e427a7b6d626d898824a09ab
4
+ data.tar.gz: eef41026be0cf4ec1db00bce32f368d52cda3863
5
+ SHA512:
6
+ metadata.gz: d1e3dad2f964a603860c5cbd8d106d47060e2c43735653dd5fda161daff4b2f9708ea77985abf29efea4af14fda20f7c369192edcd749a1f48a6a5b3beedfd85
7
+ data.tar.gz: ee295410c74e4dcf66f6e6dc4a34a485f342a6fc35ddacb37667e05ba2a01350a9dfda2bb2ec450310b707f4f371028e2b4e41771de6d4d3105bca6429c55021
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # Stuff to ignore in the test_app
14
+ test_app/tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in api_error_handler.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,96 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ api_error_handler (0.1.0)
5
+ actionpack
6
+ activesupport (>= 4.1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionpack (5.2.3)
12
+ actionview (= 5.2.3)
13
+ activesupport (= 5.2.3)
14
+ rack (~> 2.0)
15
+ rack-test (>= 0.6.3)
16
+ rails-dom-testing (~> 2.0)
17
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
+ actionview (5.2.3)
19
+ activesupport (= 5.2.3)
20
+ builder (~> 3.1)
21
+ erubi (~> 1.4)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
24
+ activesupport (5.2.3)
25
+ concurrent-ruby (~> 1.0, >= 1.0.2)
26
+ i18n (>= 0.7, < 2)
27
+ minitest (~> 5.1)
28
+ tzinfo (~> 1.1)
29
+ builder (3.2.3)
30
+ coderay (1.1.2)
31
+ concurrent-ruby (1.1.5)
32
+ crass (1.0.4)
33
+ diff-lcs (1.3)
34
+ erubi (1.8.0)
35
+ i18n (1.6.0)
36
+ concurrent-ruby (~> 1.0)
37
+ loofah (2.2.3)
38
+ crass (~> 1.0.2)
39
+ nokogiri (>= 1.5.9)
40
+ method_source (0.9.2)
41
+ mini_portile2 (2.4.0)
42
+ minitest (5.11.3)
43
+ nokogiri (1.10.3)
44
+ mini_portile2 (~> 2.4.0)
45
+ pry (0.12.2)
46
+ coderay (~> 1.1.0)
47
+ method_source (~> 0.9.0)
48
+ rack (2.0.7)
49
+ rack-test (1.1.0)
50
+ rack (>= 1.0, < 3)
51
+ rails-dom-testing (2.0.3)
52
+ activesupport (>= 4.2.0)
53
+ nokogiri (>= 1.6)
54
+ rails-html-sanitizer (1.0.4)
55
+ loofah (~> 2.2, >= 2.2.2)
56
+ railties (5.2.3)
57
+ actionpack (= 5.2.3)
58
+ activesupport (= 5.2.3)
59
+ method_source
60
+ rake (>= 0.8.7)
61
+ thor (>= 0.19.0, < 2.0)
62
+ rake (10.5.0)
63
+ rspec-core (3.8.2)
64
+ rspec-support (~> 3.8.0)
65
+ rspec-expectations (3.8.4)
66
+ diff-lcs (>= 1.2.0, < 2.0)
67
+ rspec-support (~> 3.8.0)
68
+ rspec-mocks (3.8.1)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.8.0)
71
+ rspec-rails (3.8.2)
72
+ actionpack (>= 3.0)
73
+ activesupport (>= 3.0)
74
+ railties (>= 3.0)
75
+ rspec-core (~> 3.8.0)
76
+ rspec-expectations (~> 3.8.0)
77
+ rspec-mocks (~> 3.8.0)
78
+ rspec-support (~> 3.8.0)
79
+ rspec-support (3.8.2)
80
+ thor (0.20.3)
81
+ thread_safe (0.3.6)
82
+ tzinfo (1.2.5)
83
+ thread_safe (~> 0.1)
84
+
85
+ PLATFORMS
86
+ ruby
87
+
88
+ DEPENDENCIES
89
+ api_error_handler!
90
+ bundler (~> 2.0)
91
+ pry
92
+ rake (~> 10.0)
93
+ rspec-rails (~> 3.0)
94
+
95
+ BUNDLED WITH
96
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 James Stonehill
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # ApiErrorHandler
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/api_error_handler`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'api_error_handler'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install api_error_handler
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/api_error_handler.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,33 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "api_error_handler/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "api_error_handler"
8
+ spec.version = ApiErrorHandler::VERSION
9
+ spec.authors = ["James Stonehill"]
10
+ spec.email = ["jamesstonehill@gmail.com"]
11
+
12
+ spec.summary = %q{A gem that helps you easily handle exptions in your Rails API and return informative responses to the client.}
13
+ spec.description = %q{A gem that helps you easily handle exptions in your Ruby on Rails API and return informative responses to the client by serializing exceptions into JSON and other popular API formats and returning a response with a status code that makes sense based on the exception.}
14
+ spec.homepage = "https://github.com/jamesstonehill/api_error_handler"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|test_app)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "activesupport", ">= 4.1.0"
27
+ spec.add_dependency "actionpack"
28
+
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec-rails", "~> 3.0"
32
+ spec.add_development_dependency "pry"
33
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "api_error_handler"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ require "api_error_handler/version"
2
+ require "api_error_handler/action_controller"
3
+
4
+ module ApiErrorHandler
5
+ def handle_api_errors(format: :json)
6
+
7
+ rescue_from StandardError do |exception|
8
+ render json: "caught!"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ require 'active_support/lazy_load_hooks'
2
+ require 'action_controller'
3
+
4
+ ActiveSupport.on_load :action_controller do
5
+ ::ActionController::Base.send :extend, ApiErrorHandler
6
+ ::ActionController::API.send :extend, ApiErrorHandler
7
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'serializers/json'
2
+
3
+ module ApiErrorHandler
4
+ class ErrorSerializer
5
+ SERIALIZERS_BY_FORMAT = {
6
+ json: Serializers::Json
7
+ }
8
+
9
+ def initialize(error, format, status)
10
+ @error = error
11
+ @format = format
12
+ @status = status
13
+ end
14
+
15
+ def serialize
16
+
17
+ end
18
+
19
+ private
20
+
21
+ def serializer
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,6 @@
1
+ module ApiErrorHandler
2
+ module Serializers
3
+ class Json
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module ApiErrorHandler
2
+ VERSION = "0.1.0.rc"
3
+ end
@@ -0,0 +1,9 @@
1
+ class ApiErrorHandler
2
+ module Serializers
3
+ class Json
4
+ def self.serialize(error)
5
+ { message: error.message }.to_json
6
+ end
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: api_error_handler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.rc
5
+ platform: ruby
6
+ authors:
7
+ - James Stonehill
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A gem that helps you easily handle exptions in your Ruby on Rails API
98
+ and return informative responses to the client by serializing exceptions into JSON
99
+ and other popular API formats and returning a response with a status code that makes
100
+ sense based on the exception.
101
+ email:
102
+ - jamesstonehill@gmail.com
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - ".rspec"
109
+ - ".travis.yml"
110
+ - Gemfile
111
+ - Gemfile.lock
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - api_error_handler.gemspec
116
+ - bin/console
117
+ - bin/setup
118
+ - lib/api_error_handler.rb
119
+ - lib/api_error_handler/action_controller.rb
120
+ - lib/api_error_handler/error_serializer.rb
121
+ - lib/api_error_handler/serializers/json.rb
122
+ - lib/api_error_handler/version.rb
123
+ - lib/serializers/json.rb
124
+ homepage: https://github.com/jamesstonehill/api_error_handler
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">"
140
+ - !ruby/object:Gem::Version
141
+ version: 1.3.1
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.6.14.4
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: A gem that helps you easily handle exptions in your Rails API and return
148
+ informative responses to the client.
149
+ test_files: []