micky 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/micky/errors.rb +6 -24
- data/lib/micky/request.rb +6 -0
- data/lib/micky/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 564fb6538cc477e7c8774e406b318b557ad5c9cd
|
4
|
+
data.tar.gz: 32e4dfe50c966bbe85f36f8953ff9e0492bb8c61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65b65ae98adec9f1066e44b0985a27c79f7fd5c4b1bf200d328b064acbffb952ec8b770f7c32fddaa3dd35bf16b5978ffcdeb244ec875dd6336ca5e4c46f6c4d
|
7
|
+
data.tar.gz: 52d30a340db566c8f0496109468659397474e9c77805591f3ac8cbc1d8342be88d106a9e71cf8900580a1ec05dd5c20d4e5314f97709383e471b55a34554fb7f
|
data/lib/micky/errors.rb
CHANGED
@@ -1,36 +1,16 @@
|
|
1
1
|
module Micky
|
2
2
|
class Error < StandardError
|
3
|
-
attr_reader :original_exception, :response
|
4
|
-
|
5
3
|
def initialize(message = nil, original_exception: nil, response: nil)
|
6
|
-
@original_exception = original_exception
|
7
|
-
@response = response
|
8
|
-
@message = message
|
9
|
-
end
|
10
|
-
|
11
|
-
def message
|
12
4
|
if response
|
13
|
-
"#{
|
5
|
+
super "#{response.code} #{response.message} at #{response.uri}"
|
14
6
|
elsif original_exception
|
15
|
-
original_exception.inspect
|
16
|
-
elsif
|
17
|
-
|
7
|
+
super original_exception.inspect
|
8
|
+
elsif message
|
9
|
+
super message
|
18
10
|
else
|
19
11
|
super
|
20
12
|
end
|
21
13
|
end
|
22
|
-
|
23
|
-
def request_uri
|
24
|
-
response.uri if response
|
25
|
-
end
|
26
|
-
|
27
|
-
def response_code
|
28
|
-
response.code.to_i if response
|
29
|
-
end
|
30
|
-
|
31
|
-
def response_message
|
32
|
-
response.message if response
|
33
|
-
end
|
34
14
|
end
|
35
15
|
|
36
16
|
# Client errors
|
@@ -50,4 +30,6 @@ module Micky
|
|
50
30
|
end
|
51
31
|
class TooManyRedirects < ServerError
|
52
32
|
end
|
33
|
+
class NoRedirectLocation < ServerError
|
34
|
+
end
|
53
35
|
end
|
data/lib/micky/request.rb
CHANGED
@@ -37,6 +37,12 @@ module Micky
|
|
37
37
|
previous_uri = uri
|
38
38
|
uri = response['Location']
|
39
39
|
|
40
|
+
if uri.nil?
|
41
|
+
raise Micky::NoRedirectLocation, response: response if @raise_errors
|
42
|
+
warn "Micky.#{@request_class_name.downcase}('#{previous_uri}'): No “Location” for #{response.code} response"
|
43
|
+
return nil
|
44
|
+
end
|
45
|
+
|
40
46
|
if uri !~ Micky::HTTP_URI_REGEX
|
41
47
|
if uri.start_with? '//'
|
42
48
|
# Protocol-relative
|
data/lib/micky/version.rb
CHANGED