faraday_error 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +6 -2
- data/lib/faraday_error/middleware.rb +18 -6
- data/lib/faraday_error/version.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09ccdf74e9297211ab16437b2c1b175b93ffe0c4
|
4
|
+
data.tar.gz: d3418d53d4f8d07d720d675b23ee9c0762e58a47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 549676c9dc10ed6ada555f24c4361c514aafcc3af2f6a215dbfacbe49470138c334058a832184e35482238f2022dc7e486749b399969ef89c102c520e80861fe
|
7
|
+
data.tar.gz: f75e5d6561dcae7d89f0e0fa1e5711a35ae313fc17632e07738f4b93feb66c016ed1b7744f064e6fa8e56c376ccfc959f2930a2f7902eeb145a380acd9744540
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# FaradayError
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/faraday_error.svg)](https://badge.fury.io/rb/faraday_error)
|
2
3
|
|
3
4
|
A [Faraday](https://github.com/lostisland/faraday) middleware for adding request parameters to your exception tracker.
|
4
5
|
|
@@ -37,7 +38,7 @@ end
|
|
37
38
|
And that's it. Make a request as you normally would.
|
38
39
|
```ruby
|
39
40
|
connection.post do |req|
|
40
|
-
req.url '/503'
|
41
|
+
req.url '/503'
|
41
42
|
req.headers['Content-Type'] = 'application/json'
|
42
43
|
req.body = JSON.generate(abc: "xyz")
|
43
44
|
end
|
@@ -58,7 +59,8 @@ If any request fails, Honeybadger's "context" for this error will include your r
|
|
58
59
|
"abc": "xyz"
|
59
60
|
}
|
60
61
|
}
|
61
|
-
}
|
62
|
+
}
|
63
|
+
```
|
62
64
|
|
63
65
|
|
64
66
|
## Development
|
@@ -67,6 +69,8 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
67
69
|
|
68
70
|
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).
|
69
71
|
|
72
|
+
The included [RestReflector](../master/spec/rest_reflector.rb) Sinatra app is suitable for making requests that are guaranteed to fail in particlar ways.
|
73
|
+
|
70
74
|
## Contributing
|
71
75
|
|
72
76
|
Bug reports and pull requests are welcome on GitHub at https://github.com/jelder/faraday_error. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module FaradayError
|
2
4
|
class Middleware
|
3
5
|
|
6
|
+
MAX_PARSED_BODY_LENGTH = (1*1024*1024).freeze
|
7
|
+
|
4
8
|
def initialize(app, options = {})
|
5
9
|
@app = app
|
6
10
|
@name = options.fetch(:name, 'faraday')
|
@@ -21,17 +25,25 @@ module FaradayError
|
|
21
25
|
end
|
22
26
|
|
23
27
|
def context_from_env(env)
|
28
|
+
body_length = String(env[:body]).length
|
24
29
|
context = {
|
25
30
|
method: env[:method],
|
26
31
|
url: env[:url],
|
27
32
|
request_headers: env[:request_headers],
|
28
|
-
body_length:
|
33
|
+
body_length: body_length,
|
29
34
|
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
if 2 < body_length && body_length < MAX_PARSED_BODY_LENGTH
|
36
|
+
begin
|
37
|
+
context[:body] = case env[:request_headers]["Content-Type"]
|
38
|
+
when "application/json" then JSON.parse(env[:body])
|
39
|
+
when "application/x-www-form-urlencoded" then URI.decode_www_form(env[:body]).to_h
|
40
|
+
end
|
41
|
+
rescue => ex
|
42
|
+
puts ex.inspect
|
43
|
+
puts ex.backtrace
|
44
|
+
ensure
|
45
|
+
context[:body] ||= env[:body]
|
46
|
+
end
|
35
47
|
end
|
36
48
|
return context
|
37
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday_error
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Elder
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -128,6 +128,7 @@ dependencies:
|
|
128
128
|
version: 3.14.0
|
129
129
|
description: |+
|
130
130
|
# FaradayError
|
131
|
+
[![Gem Version](https://badge.fury.io/rb/faraday_error.svg)](https://badge.fury.io/rb/faraday_error)
|
131
132
|
|
132
133
|
A [Faraday](https://github.com/lostisland/faraday) middleware for adding request parameters to your exception tracker.
|
133
134
|
|
@@ -166,7 +167,7 @@ description: |+
|
|
166
167
|
And that's it. Make a request as you normally would.
|
167
168
|
```ruby
|
168
169
|
connection.post do |req|
|
169
|
-
req.url '/503'
|
170
|
+
req.url '/503'
|
170
171
|
req.headers['Content-Type'] = 'application/json'
|
171
172
|
req.body = JSON.generate(abc: "xyz")
|
172
173
|
end
|
@@ -187,7 +188,8 @@ description: |+
|
|
187
188
|
"abc": "xyz"
|
188
189
|
}
|
189
190
|
}
|
190
|
-
}
|
191
|
+
}
|
192
|
+
```
|
191
193
|
|
192
194
|
|
193
195
|
## Development
|
@@ -196,6 +198,8 @@ description: |+
|
|
196
198
|
|
197
199
|
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).
|
198
200
|
|
201
|
+
The included [RestReflector](../master/spec/rest_reflector.rb) Sinatra app is suitable for making requests that are guaranteed to fail in particlar ways.
|
202
|
+
|
199
203
|
## Contributing
|
200
204
|
|
201
205
|
Bug reports and pull requests are welcome on GitHub at https://github.com/jelder/faraday_error. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|