namira 1.1.0 → 1.2.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: f15da8cadfc98f548c2da00e94dc548b8832c40a
4
- data.tar.gz: d8d5f07ff220028dc41a625e50bab2bd614ceb60
3
+ metadata.gz: cd40f31fd9c696c000f54eeb83a09db3c4213222
4
+ data.tar.gz: a707df33c8946cb12d735e7ba9ec5204c54ae3fc
5
5
  SHA512:
6
- metadata.gz: f7daed40792bb0fd62e2989fe193ad16d3398029f9b5c70a034b551b10ff463432162bf309a6219a5effbfc118341acbc2449c3229faac024d5e52b08296a376
7
- data.tar.gz: 109fe7e6579b3c59598f4391009d2b18cbe18a8408b79589d0cd50b86eca25c814f757c8262f5d3707a66c70c66785435fde516bf79d555f73c26fc09f705ac1
6
+ metadata.gz: 8149d922e3f943da4717c04df6aca73d51b27a8a45e69108e37b2d47bb35624e31638df989ca102b7288bb9c2524938509a7e1263406dd957357b1edf62b54c4
7
+ data.tar.gz: faca22f4f42291a472e2c19486b2953648e9dd29116a9f49b282d96eee27906b87994b89f7e240dcead130e357d88d67399145cc769179a9dd0bc65edfb134c2
@@ -1,3 +1,7 @@
1
+ # 1.2 (2019-01-18)
2
+
3
+ * Auto add Bugsnag error information
4
+
1
5
  # 1.1 (2018-05-18)
2
6
 
3
7
  * Make HTTP Errors their own class.
@@ -1,5 +1,6 @@
1
1
  require 'namira/config'
2
2
  require 'namira/env'
3
+ require 'namira/error_helpers'
3
4
  require 'namira/errors'
4
5
  require 'namira/middleware'
5
6
  require 'namira/query_builder'
@@ -0,0 +1,38 @@
1
+ begin
2
+ require 'bugsnag'
3
+ rescue LoadError
4
+ end
5
+
6
+ require_relative 'errors'
7
+
8
+ if defined?(::Bugsnag)
9
+ module Namira
10
+ module ErrorHelpers
11
+ class Bugsnag
12
+ def initialize(bugsnag)
13
+ @bugsnag = bugsnag
14
+ end
15
+
16
+ def call(notification)
17
+ notification.exceptions.each do |exception|
18
+ next unless exception.is_a?(Namira::Errors::HTTPError)
19
+
20
+ notification.add_tab("Namira #{exception.response.status.to_i}", {
21
+ headers: exception.response.headers.to_h,
22
+ body: exception.response.body.to_s[0...200],
23
+ method: exception.response.method.to_s,
24
+ url: exception.response.url.to_s,
25
+ redirected: (exception.response.redirect_count > 0).to_s
26
+ })
27
+ end
28
+
29
+ @bugsnag.call(notification)
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ ::Bugsnag.configure do |config|
36
+ config.middleware.use Namira::ErrorHelpers::Bugsnag
37
+ end
38
+ end
@@ -32,18 +32,29 @@ module Namira
32
32
  klass_for_status(response.status).new("http_error/#{response.status}", response.status, response)
33
33
  end
34
34
 
35
+ def generate_custom_classes
36
+ STATUS_MAPPING.each do |_, value|
37
+ klass_name = "#{value.tr(' ', '')}Error"
38
+ begin
39
+ HTTPError.const_get(klass_name)
40
+ rescue NameError
41
+ klass = Class.new(HTTPError) {}
42
+ HTTPError.const_set(klass_name, klass)
43
+ end
44
+ end
45
+ end
46
+
35
47
  private
36
48
 
37
49
  def klass_for_status(status)
38
50
  name = STATUS_MAPPING[status.to_i.to_s]
39
51
  return HTTPError if name.nil?
52
+
40
53
  klass_name = "#{name.tr(' ', '')}Error"
41
54
  begin
42
55
  HTTPError.const_get(klass_name)
43
56
  rescue NameError
44
- klass = Class.new(HTTPError) {}
45
- HTTPError.const_set(klass_name, klass)
46
- retry
57
+ return HTTPError
47
58
  end
48
59
  end
49
60
  end
@@ -101,3 +112,5 @@ module Namira
101
112
  end
102
113
  end
103
114
  end
115
+
116
+ Namira::Errors::HTTPError.generate_custom_classes
@@ -12,16 +12,20 @@ module Namira
12
12
  #
13
13
  # @param env [Namira::Env] The request environment
14
14
  def call(env)
15
- handle_response(env.response)
16
- env.response = Namira::Response.new(env.response)
15
+ env.response = handle_response(env)
17
16
  @app.call(env)
18
17
  end
19
18
 
20
19
  private
21
20
 
22
- def handle_response(response)
23
- final = Namira::Response.new(response)
24
- if (200...300).cover?(response.status)
21
+ def handle_response(env)
22
+ final = Namira::Response.new(
23
+ env.method,
24
+ env.uri,
25
+ env.redirect_count,
26
+ env.response
27
+ )
28
+ if (200...300).cover?(env.response.status)
25
29
  final
26
30
  else
27
31
  raise Errors::HTTPError.create(final)
@@ -2,9 +2,18 @@ module Namira
2
2
  ##
3
3
  # HTTP response
4
4
  class Response
5
+ attr_reader :method
6
+
7
+ attr_reader :url
8
+
9
+ attr_reader :redirect_count
10
+
5
11
  ##
6
12
  # Create a new {Namira::Response}
7
- def initialize(backing)
13
+ def initialize(method, url, redirect_count, backing)
14
+ @method = method
15
+ @url = url
16
+ @redirect_count = redirect_count
8
17
  @backing = backing
9
18
  end
10
19
 
@@ -1,5 +1,5 @@
1
1
  module Namira
2
2
  ##
3
3
  # The current version of Namira
4
- VERSION = '1.1.0'.freeze
4
+ VERSION = '1.2.0'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namira
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skylar Schipper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-11 00:00:00.000000000 Z
11
+ date: 2019-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -150,6 +150,7 @@ files:
150
150
  - lib/namira.rb
151
151
  - lib/namira/config.rb
152
152
  - lib/namira/env.rb
153
+ - lib/namira/error_helpers.rb
153
154
  - lib/namira/errors.rb
154
155
  - lib/namira/errors/base_error.rb
155
156
  - lib/namira/errors/http_error.rb
@@ -191,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  version: '0'
192
193
  requirements: []
193
194
  rubyforge_project:
194
- rubygems_version: 2.5.2
195
+ rubygems_version: 2.5.2.3
195
196
  signing_key:
196
197
  specification_version: 4
197
198
  summary: A simple wrapper around HTTP