api_error_handler 0.1.0.rc → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 136050d80b1f4f57e427a7b6d626d898824a09ab
4
- data.tar.gz: eef41026be0cf4ec1db00bce32f368d52cda3863
3
+ metadata.gz: 9be82ce1e320cfcf1a01d61211f628087cc67ea5
4
+ data.tar.gz: c1ba01e3184c4e1b02aa44da16c9a48ba27be409
5
5
  SHA512:
6
- metadata.gz: d1e3dad2f964a603860c5cbd8d106d47060e2c43735653dd5fda161daff4b2f9708ea77985abf29efea4af14fda20f7c369192edcd749a1f48a6a5b3beedfd85
7
- data.tar.gz: ee295410c74e4dcf66f6e6dc4a34a485f342a6fc35ddacb37667e05ba2a01350a9dfda2bb2ec450310b707f4f371028e2b4e41771de6d4d3105bca6429c55021
6
+ metadata.gz: 417b51a2dec65912d6e0ff9b8e3865aa59d14897b54ee3cbaa07f6f3de987a92023210602d7480627eff200438e4a91b654e798859480b78c5d9a0617d0065a2
7
+ data.tar.gz: 3d06ed46fbc62e48b8601f416298edfaa80d9c6a0aac75038c63f9da94d42e9fb3242ff05b3f86c70569eee7a539c5fa64a839dd232cab3e55eab90934234652
data/.gitignore CHANGED
@@ -7,8 +7,13 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
 
10
+ /Gemfile.lock
11
+
10
12
  # rspec failure tracking
11
13
  .rspec_status
12
14
 
13
15
  # Stuff to ignore in the test_app
14
16
  test_app/tmp
17
+ test_app/log
18
+ test_app/.byebug_history
19
+ test_app/log/development.log
data/.travis.yml CHANGED
@@ -1,7 +1,10 @@
1
1
  ---
2
2
  sudo: false
3
3
  language: ruby
4
- cache: bundler
5
4
  rvm:
6
- - 2.6.3
7
- before_install: gem install bundler -v 2.0.1
5
+ - 2.4
6
+ cache: bundler
7
+ before_install:
8
+ - gem update --system
9
+ - gem install bundler
10
+ script: ./bin/test.sh
data/README.md CHANGED
@@ -1,8 +1,26 @@
1
1
  # ApiErrorHandler
2
+ [![Build Status](https://travis-ci.org/jamesstonehill/api_error_handler.svg?branch=master)](https://travis-ci.org/jamesstonehill/api_error_handler)
2
3
 
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
+ Are your API error responses not all that you want them to be? If so, you've
5
+ found the right gem! `api_error_handler` handles all aspects of returning
6
+ informative, spec-compliant responses to clients when your application
7
+ encounters an error in the course of processing a response.
4
8
 
5
- TODO: Delete this and the text above, and describe your gem
9
+ This "handling" includes:
10
+ - __Error serialization__: each response will include a response body that
11
+ gives some information on the type of error that your application
12
+ encountered. See the [Responses Body Options](#response-body-options)
13
+ section for details and configuration options.
14
+ - __Status code setting__: `api_error_handler` will set the HTTP status code of
15
+ the response based on the type of error that is raised. For example, when an
16
+ `ActiveRecord::RecordNotFound` error is raised, it will set the response
17
+ status to 404. See the [HTTP Status Mapping](#http-status-mapping) section
18
+ for details and configuration options.
19
+ - __Error reporting__: If you use a 3rd party bug tracking
20
+ tool like Honeybadger or Sentry, `api_error_handler` will notify this
21
+ service of the error for you so you don't have to!
22
+ - __Content type setting__: `api_error_handler` will set the content type of the
23
+ response based on the format of response body.
6
24
 
7
25
  ## Installation
8
26
 
@@ -14,25 +32,260 @@ gem 'api_error_handler'
14
32
 
15
33
  And then execute:
16
34
 
17
- $ bundle
35
+ $ bundle install
18
36
 
19
- Or install it yourself as:
37
+ ## Usage
20
38
 
21
- $ gem install api_error_handler
39
+ To get started, all you need to do is invoke `handle_api_errors` inside your
40
+ controller like so:
22
41
 
23
- ## Usage
42
+ ```ruby
43
+ class MyController < ActionController::API
44
+ handle_api_errors()
45
+
46
+ def index
47
+ raise "Something is very very wrong!"
48
+ end
49
+ end
50
+ ```
51
+
52
+ Now when you go to `MyController#index`, your API will return the following
53
+ response:
54
+
55
+ ```json
56
+ HTTP/1.1 500 Internal Server Error
57
+ Content-Type: application/json
58
+
59
+ {
60
+ "error": {
61
+ "title":"Internal Server Error",
62
+ "detail":"Something is very very wrong!"
63
+ }
64
+ }
65
+ ```
66
+
67
+ ### Error handling options
68
+
69
+ `handle_api_errors` implements a bunch of (hopefully) sensible defaults so that
70
+ all you need to do is invoke `handle_api_errors()` in your controller to get
71
+ useful error handling! However, in all likelihood you'll want to override some
72
+ of these options. This section gives details on the various options available
73
+ for configuring the `api_error_handler`.
74
+
75
+ #### Response Body Options
76
+ By default, `handle_api_errors` picks the `:json` format for serializing errors.
77
+ However, this gem comes with a number of other formats for serializing your
78
+ errors.
79
+
80
+ ##### JSON (the default)
81
+ ```ruby
82
+ handle_api_errors(format: :json)
83
+ # Or
84
+ handle_api_errors()
85
+ ```
86
+
87
+ ```json
88
+ HTTP/1.1 500 Internal Server Error
89
+ Content-Type: application/json
90
+
91
+ {
92
+ "error": {
93
+ "title":"Internal Server Error",
94
+ "detail":"Something is very very wrong!"
95
+ }
96
+ }
97
+ ```
24
98
 
25
- TODO: Write usage instructions here
99
+ ##### JSON:API
100
+ If your API follows the `JSON:API` spec, you'll want to use the `:json_api`
101
+ format option.
26
102
 
27
- ## Development
103
+ ```ruby
104
+ handle_api_errors(format: :json_api)
105
+ ```
28
106
 
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.
107
+ Responses with this format will follow the `JSON:API` [specification for error
108
+ objects](https://jsonapi.org/format/#error-objects). This will look something
109
+ like this:
30
110
 
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).
111
+ ```json
112
+ HTTP/1.1 500 Internal Server Error
113
+ Content-Type: application/vnd.api+json
114
+
115
+ {
116
+ "errors": [
117
+ {
118
+ "status":"500",
119
+ "title":"Internal Server Error",
120
+ "detail":"Something is very very wrong!"
121
+ }
122
+ ]
123
+ }
124
+ ```
32
125
 
33
- ## Contributing
126
+ ##### XML
127
+ ```ruby
128
+ handle_api_errors(format: :xml)
129
+ ```
130
+
131
+ ```xml
132
+ <?xml version="1.0" encoding="UTF-8"?>
133
+ <Error>
134
+ <Title>Internal Server Error</title>
135
+ <Detail>Something is very very wrong!</detail>
136
+ </Error>
137
+ ```
138
+
139
+ ##### Custom Error Responses
140
+ If none of the out-of-the-box options suit you then you can pass in your own
141
+ error serializer like so:
142
+
143
+ ```ruby
144
+ handle_api_errors(serializer: MyCustomErrorSerializer)
145
+ ```
146
+
147
+ The custom serializer must implement two instance methods, `serialize` and
148
+ `render_format`. The `serialize` method should return the body of the response
149
+ you want to render. The `render_format` should be the format that you want to
150
+ render the response in (e.g `:json`, `:xml`, `:plain`), which will be passed to
151
+ Rails' `render` method.
152
+
153
+ It is recommended you inherit your serializer from
154
+ `ApiErrorHandler::Serializers::BaseSerializer` to gain some helpful instance
155
+ methods and defaults.
156
+
157
+ ```ruby
158
+ class MyCustomErrorSerializer < ApiErrorHandler::Serializers::BaseSerializer
159
+ def serialize(serializer_options)
160
+ # The `title` and `status_code` come from the BaseSerializer.
161
+ "Error! Title: #{title} Status Code: #{status_code}"
162
+ end
34
163
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/api_error_handler.
164
+ def render_format
165
+ :plain
166
+ end
167
+ end
168
+ ```
169
+ ##### Backtraces
170
+ If you want to include the error's backtrace in the response body:
171
+
172
+ ```ruby
173
+ handle_api_errors(backtrace: true)
174
+ ```
175
+
176
+ ```json
177
+ {
178
+ "error": {
179
+ "title":"Internal Server Error",
180
+ "detail":"Something is very very wrong!",
181
+ "backtrace": [
182
+ # The backtrace
183
+ ]
184
+ }
185
+ }
186
+ ```
187
+
188
+ ### HTTP Status Mapping
189
+
190
+ Most of the time, you'll want to set the HTTP status code based on the type of
191
+ error being raised. To determine which errors map to which status codes,
192
+ `api_error_handler` uses `ActionDispatch::ExceptionWrapper.rescue_responses`. If
193
+ you're using Rails with ActiveRecord, by default this includes:
194
+
195
+ ```ruby
196
+ {
197
+ "ActionController::RoutingError" => :not_found,
198
+ "AbstractController::ActionNotFound" => :not_found,
199
+ "ActionController::MethodNotAllowed" => :method_not_allowed,
200
+ "ActionController::UnknownHttpMethod" => :method_not_allowed,
201
+ "ActionController::NotImplemented" => :not_implemented,
202
+ "ActionController::UnknownFormat" => :not_acceptable,
203
+ "Mime::Type::InvalidMimeType" => :not_acceptable,
204
+ "ActionController::MissingExactTemplate" => :not_acceptable,
205
+ "ActionController::InvalidAuthenticityToken" => :unprocessable_entity,
206
+ "ActionController::InvalidCrossOriginRequest" => :unprocessable_entity,
207
+ "ActionDispatch::Http::Parameters::ParseError" => :bad_request,
208
+ "ActionController::BadRequest" => :bad_request,
209
+ "ActionController::ParameterMissing" => :bad_request,
210
+ "Rack::QueryParser::ParameterTypeError" => :bad_request,
211
+ "Rack::QueryParser::InvalidParameterError" => :bad_request
212
+ "ActiveRecord::RecordNotFound" => :not_found,
213
+ "ActiveRecord::StaleObjectError" => :conflict,
214
+ "ActiveRecord::RecordInvalid" => :unprocessable_entity,
215
+ "ActiveRecord::RecordNotSaved" => :unprocessable_entity
216
+ }
217
+ ```
218
+ - https://guides.rubyonrails.org/configuring.html#configuring-action-dispatch
219
+
220
+ You can add to this mapping on an application level by doing the following:
221
+ ```ruby
222
+ config.action_dispatch.rescue_responses.merge!(
223
+ "AuthenticationError" => :not_authorized
224
+ )
225
+ ```
226
+
227
+ Now when an you raise an `AuthenticationError` in one of your actions, the
228
+ status code of the response will be 401.
229
+
230
+ ### Error Reporting
231
+ If you use an external error tracking software like Sentry or Honeybadger you'll
232
+ want to report all errors to that service.
233
+
234
+ You can do so by passing in a `Proc` to the `error_reporter` option. The first
235
+ argument provided to the Proc will be the error. The second argument will be the
236
+ `error_id` if you have one. See the section below for more details on error IDs.
237
+
238
+ ```ruby
239
+ handle_api_errors(
240
+ error_reporter: Proc.new do |error, error_id|
241
+ Raven.capture_exception(error, error_id: error_id)
242
+ end
243
+ )
244
+ ```
245
+
246
+ ### Error IDs
247
+ Sometimes it's helpful to include IDs with your error responses so that you can
248
+ correlate a specific error with a record in your logs or bug tracking software.
249
+
250
+ ```ruby
251
+ handle_api_errors(
252
+ error_id: Proc.new { |error| SecureRandom.uuid }
253
+ )
254
+ ```
255
+
256
+ ```json
257
+ {
258
+ "error": {
259
+ "title": "Internal Server Error",
260
+ "detail": "Something is very very wrong!",
261
+ "id": "4ab520f2-ae33-4539-9371-ea21aada5582"
262
+ }
263
+ }
264
+ ```
265
+
266
+ ### Setting Content Type
267
+ The api_error_handler will set the content type of your error based on the
268
+ `format` option you pick. However, you can override this by setting the
269
+ `content_type` option if you wish.
270
+
271
+ ```ruby
272
+ handle_api_errors(
273
+ format: :json,
274
+ content_type: 'application/vnd.api+json'
275
+ )
276
+ ```
277
+
278
+ ```json
279
+ HTTP/1.1 500 Internal Server Error
280
+ Content-Type: application/vnd.api+json
281
+
282
+ {
283
+ "error": {
284
+ "title":"Internal Server Error",
285
+ "detail":"Something is very very wrong!"
286
+ }
287
+ }
288
+ ```
36
289
 
37
290
  ## License
38
291
 
@@ -7,10 +7,11 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "api_error_handler"
8
8
  spec.version = ApiErrorHandler::VERSION
9
9
  spec.authors = ["James Stonehill"]
10
- spec.email = ["jamesstonehill@gmail.com"]
10
+ spec.email = ["james.stonehill@gmail.com"]
11
+ spec.required_ruby_version = '~> 2.2'
11
12
 
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.}
13
+ spec.summary = %q{A gem that helps you easily handle exceptions in your Rails API and return informative responses to the client.}
14
+ spec.description = %q{A gem that helps you easily handle exceptions 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
15
  spec.homepage = "https://github.com/jamesstonehill/api_error_handler"
15
16
  spec.license = "MIT"
16
17
 
@@ -23,11 +24,11 @@ Gem::Specification.new do |spec|
23
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
25
  spec.require_paths = ["lib"]
25
26
 
26
- spec.add_dependency "activesupport", ">= 4.1.0"
27
- spec.add_dependency "actionpack"
27
+ spec.add_dependency "activesupport", ">= 4.0"
28
+ spec.add_dependency "actionpack", ">= 4.0"
29
+ spec.add_dependency "rack", ">= 1.0"
28
30
 
29
31
  spec.add_development_dependency "bundler", "~> 2.0"
30
32
  spec.add_development_dependency "rake", "~> 10.0"
31
33
  spec.add_development_dependency "rspec-rails", "~> 3.0"
32
- spec.add_development_dependency "pry"
33
34
  end
data/bin/test.sh ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+ bundle install && bundle exec rspec
3
+ bundle install --gemfile ./test_app/Gemfile && bundle exec --gemfile ./test_app/Gemfile rspec
@@ -1,11 +1,54 @@
1
- require "api_error_handler/version"
2
- require "api_error_handler/action_controller"
1
+ require_relative "./api_error_handler/version"
2
+ require_relative "./api_error_handler/action_controller"
3
+ Dir[File.join(__dir__, 'api_error_handler', 'serializers', "*.rb")].each { |file| require file }
3
4
 
4
5
  module ApiErrorHandler
5
- def handle_api_errors(format: :json)
6
+ SERIALIZERS_BY_FORMAT = {
7
+ json: Serializers::Json,
8
+ json_api: Serializers::JsonApi,
9
+ xml: Serializers::Xml,
10
+ }.freeze
6
11
 
7
- rescue_from StandardError do |exception|
8
- render json: "caught!"
12
+ SERIALIZER_OPTIONS = {
13
+ backtrace: false,
14
+ }.freeze
15
+
16
+ CONTENT_TYPE_BY_FORMAT = {
17
+ json_api: "application/vnd.api+json"
18
+ }.freeze
19
+
20
+ def handle_api_errors(options = {})
21
+ format = options.fetch(:format, :json)
22
+ status_mapping = ActionDispatch::ExceptionWrapper.rescue_responses
23
+ error_reporter = options[:error_reporter]
24
+ serializer_options = SERIALIZER_OPTIONS.merge(
25
+ options.slice(*SERIALIZER_OPTIONS.keys)
26
+ )
27
+
28
+ serializer_class = options[:serializer] || SERIALIZERS_BY_FORMAT.fetch(format)
29
+ content_type = options[:content_type] || CONTENT_TYPE_BY_FORMAT[format]
30
+
31
+ rescue_from StandardError do |error|
32
+ begin
33
+ status = status_mapping[error.class.to_s]
34
+
35
+ error_id = nil
36
+ error_id = options[:error_id].call(error) if options[:error_id]
37
+ error_reporter.call(error, error_id) if error_reporter
38
+
39
+ serializer = serializer_class.new(error, status)
40
+ response_body = serializer.serialize(
41
+ serializer_options.merge(error_id: error_id)
42
+ )
43
+
44
+ render(
45
+ serializer.render_format => response_body,
46
+ content_type: content_type,
47
+ status: status
48
+ )
49
+ rescue
50
+ raise error
51
+ end
9
52
  end
10
53
  end
11
54
  end
@@ -0,0 +1,3 @@
1
+ module ApiErrorHandler
2
+ # class UnknownSerializerError < ArgumentError; end
3
+ end
@@ -0,0 +1,22 @@
1
+ require 'rack/utils'
2
+
3
+ module ApiErrorHandler
4
+ module Serializers
5
+ class BaseSerializer
6
+ DEFAULT_STATUS_CODE = "500".freeze
7
+
8
+ def initialize(error, status)
9
+ @error = error
10
+ @status = status
11
+ end
12
+
13
+ def status_code
14
+ Rack::Utils::SYMBOL_TO_STATUS_CODE.fetch(@status, DEFAULT_STATUS_CODE).to_s
15
+ end
16
+
17
+ def title
18
+ Rack::Utils::HTTP_STATUS_CODES.fetch(status_code.to_i)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,6 +1,32 @@
1
+ require_relative './base_serializer'
2
+
1
3
  module ApiErrorHandler
2
4
  module Serializers
3
- class Json
5
+ class Json < BaseSerializer
6
+ # There is no official spec that governs this error response format so
7
+ # this serializer is just trying to impliment a simple response with
8
+ # sensible defaults.
9
+ #
10
+ # I borrowed heavily from Facebook's error response format since it seems
11
+ # to be a reasonable approach for a simple light-weight error response.
12
+
13
+ def serialize(options = {})
14
+ body = {
15
+ error: {
16
+ title: title,
17
+ detail: @error.message,
18
+ }
19
+ }
20
+
21
+ body[:error][:id] = options[:error_id] if options[:error_id]
22
+ body[:error][:backtrace] = @error.backtrace if options[:backtrace]
23
+
24
+ body.to_json
25
+ end
26
+
27
+ def render_format
28
+ :json
29
+ end
4
30
  end
5
31
  end
6
32
  end
@@ -0,0 +1,28 @@
1
+ require_relative './base_serializer'
2
+
3
+ module ApiErrorHandler
4
+ module Serializers
5
+ class JsonApi < BaseSerializer
6
+ def serialize(options = {})
7
+ body = {
8
+ errors: [
9
+ {
10
+ status: status_code,
11
+ title: title,
12
+ detail: @error.message,
13
+ }
14
+ ]
15
+ }
16
+
17
+ body[:errors].first[:id] = options[:error_id] if options[:error_id]
18
+ body[:errors].first[:meta] = { backtrace: @error.backtrace } if options[:backtrace]
19
+
20
+ body.to_json
21
+ end
22
+
23
+ def render_format
24
+ :json
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'active_support/core_ext/hash/conversions'
2
+ require_relative './base_serializer'
3
+
4
+ module ApiErrorHandler
5
+ module Serializers
6
+ class Xml < BaseSerializer
7
+ def serialize(options = {})
8
+ body = {
9
+ Title: title,
10
+ Detail: @error.message,
11
+ }
12
+
13
+ body[:Id] = options[:error_id] if options[:error_id]
14
+ body[:Backtrace] = @error.backtrace if options[:backtrace]
15
+
16
+ body.to_xml(root: "Error")
17
+ end
18
+
19
+ def render_format
20
+ :xml
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module ApiErrorHandler
2
- VERSION = "0.1.0.rc"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_error_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.rc
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Stonehill
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-20 00:00:00.000000000 Z
11
+ date: 2019-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,28 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.0
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.1.0
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: actionpack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '4.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,26 +94,12 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  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
97
+ description: A gem that helps you easily handle exceptions in your Ruby on Rails API
98
98
  and return informative responses to the client by serializing exceptions into JSON
99
99
  and other popular API formats and returning a response with a status code that makes
100
100
  sense based on the exception.
101
101
  email:
102
- - jamesstonehill@gmail.com
102
+ - james.stonehill@gmail.com
103
103
  executables: []
104
104
  extensions: []
105
105
  extra_rdoc_files: []
@@ -108,19 +108,21 @@ files:
108
108
  - ".rspec"
109
109
  - ".travis.yml"
110
110
  - Gemfile
111
- - Gemfile.lock
112
111
  - LICENSE.txt
113
112
  - README.md
114
113
  - Rakefile
115
114
  - api_error_handler.gemspec
116
115
  - bin/console
117
116
  - bin/setup
117
+ - bin/test.sh
118
118
  - lib/api_error_handler.rb
119
119
  - lib/api_error_handler/action_controller.rb
120
- - lib/api_error_handler/error_serializer.rb
120
+ - lib/api_error_handler/errors.rb
121
+ - lib/api_error_handler/serializers/base_serializer.rb
121
122
  - lib/api_error_handler/serializers/json.rb
123
+ - lib/api_error_handler/serializers/json_api.rb
124
+ - lib/api_error_handler/serializers/xml.rb
122
125
  - lib/api_error_handler/version.rb
123
- - lib/serializers/json.rb
124
126
  homepage: https://github.com/jamesstonehill/api_error_handler
125
127
  licenses:
126
128
  - MIT
@@ -131,19 +133,19 @@ require_paths:
131
133
  - lib
132
134
  required_ruby_version: !ruby/object:Gem::Requirement
133
135
  requirements:
134
- - - ">="
136
+ - - "~>"
135
137
  - !ruby/object:Gem::Version
136
- version: '0'
138
+ version: '2.2'
137
139
  required_rubygems_version: !ruby/object:Gem::Requirement
138
140
  requirements:
139
- - - ">"
141
+ - - ">="
140
142
  - !ruby/object:Gem::Version
141
- version: 1.3.1
143
+ version: '0'
142
144
  requirements: []
143
145
  rubyforge_project:
144
146
  rubygems_version: 2.6.14.4
145
147
  signing_key:
146
148
  specification_version: 4
147
- summary: A gem that helps you easily handle exptions in your Rails API and return
149
+ summary: A gem that helps you easily handle exceptions in your Rails API and return
148
150
  informative responses to the client.
149
151
  test_files: []
data/Gemfile.lock DELETED
@@ -1,96 +0,0 @@
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
@@ -1,25 +0,0 @@
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
@@ -1,9 +0,0 @@
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