better-faraday 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/better-faraday.gemspec +1 -1
- data/lib/better-faraday.rb +18 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 520161498209165aa279351373198c4f82936380767f5bbffa6bd02e9698527f
|
4
|
+
data.tar.gz: aadd3384613e59c8855b8432895c5ac6ef2a2afbbeddd82d689ddd05022be2be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be5bd473d0551db70328a71d4b1ae0a880de59ee0b60fc8826d2899583f771b66300d59c71c9e48ac833c16854c964cda23b6e25bad4a0811a221721b9bcb3c6
|
7
|
+
data.tar.gz: e329ceb0a76522e17d52502ec5e13a2bad7d14c9b2c5b887e7a1d042e6dfb59e80ecc7b0fdd27eae50d347733c20a66d2fb255d748eee1955f294ba0a70a21c4
|
data/better-faraday.gemspec
CHANGED
data/lib/better-faraday.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require "faraday"
|
5
4
|
require "json"
|
5
|
+
require "faraday"
|
6
|
+
require "faraday/error"
|
7
|
+
require "faraday/options"
|
8
|
+
require "faraday/response"
|
6
9
|
|
7
10
|
Module.new do
|
8
11
|
def run_request(method, url, body, headers, &block)
|
@@ -15,12 +18,23 @@ module Faraday
|
|
15
18
|
attr_reader :request_body
|
16
19
|
end
|
17
20
|
|
21
|
+
class Error
|
22
|
+
attr_reader :response
|
23
|
+
end
|
24
|
+
|
18
25
|
class Response
|
19
26
|
def assert_2xx!
|
20
27
|
return self if status >= 200 && status <= 299
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
klass = if status == 422
|
29
|
+
Faraday::HTTP422
|
30
|
+
elsif status >= 400 && status <= 499
|
31
|
+
Faraday::HTTP4xx
|
32
|
+
else
|
33
|
+
Faraday::Error
|
34
|
+
end
|
35
|
+
error = klass.new(describe)
|
36
|
+
error.instance_variable_set(:@response, self)
|
37
|
+
raise error
|
24
38
|
end
|
25
39
|
|
26
40
|
alias ok! assert_2xx! # Short name.
|