grac 2.2.2 → 2.3.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: 280ed2bb063aec54e36cdbae1273eed77bf6d7a8
4
- data.tar.gz: a3f5f241c7b34fe9f1bb22de72b15b199038def1
3
+ metadata.gz: c4258aeb15110d2f08abd1deecca0f6564d7fdf8
4
+ data.tar.gz: 539a32d74b6ee5af8a338e23a13e52bc0cf6c8dc
5
5
  SHA512:
6
- metadata.gz: 00fac6601b78e14c03f9f6e12010675187d664d59c46e928ac84dee53b65a4cc66f03c526b9c1ecd89976b95fc39d76ded2f35faab1c4fd0b050c717ee64e884
7
- data.tar.gz: 36cc32054886343c9d792eab5b7b24aeeb3a7c935c703b0742dd6d6317b6bff49ddea6d783a60b5f509bea9f7b35cad1cf1d7378a49baeed8a26b2a47f3d53f1
6
+ metadata.gz: 5c07949577cc3d0afd62a0fe6c78893e1077399d6c25385253b712114201c7d2d71af2dd2c6b04ca014d0cb900407b7e8f6ac60e81051ed6a1ff72d0632832c7
7
+ data.tar.gz: 1d2f35dd0bafdf139751827345cd87c4d3f11c50d4bf471958e5a40a4033274fe81bc69dc27c109c6af32cf606f3a5b3786eefc178a83592394186ed60236e14
@@ -1,2 +1,2 @@
1
- require 'grac/version'
2
- require 'grac/client'
1
+ require_relative 'grac/version'
2
+ require_relative 'grac/client'
@@ -126,16 +126,32 @@ module Grac
126
126
  return true
127
127
  when 0
128
128
  raise Exception::RequestFailed.new(method, response.effective_url, response.return_message)
129
- when 400
130
- raise Exception::BadRequest.new(method, response.effective_url, response.parsed_or_raw_body)
131
- when 403
132
- raise Exception::Forbidden.new(method, response.effective_url, response.parsed_or_raw_body)
133
- when 404
134
- raise Exception::NotFound.new(method, response.effective_url, response.parsed_or_raw_body)
135
- when 409
136
- raise Exception::Conflict.new(method, response.effective_url, response.parsed_or_raw_body)
137
129
  else
138
- raise Exception::ServiceError.new(method, response.effective_url, response.parsed_or_raw_body)
130
+ begin
131
+ # The Response class doesn't have enough information to create a proper exception, so
132
+ # catch its exception and raise a proper one.
133
+ parsed_body = response.parsed_json
134
+ rescue Exception::InvalidContent
135
+ raise Exception::ErrorWithInvalidContent.new(
136
+ method,
137
+ response.effective_url,
138
+ response.code,
139
+ response.body,
140
+ 'json'
141
+ )
142
+ end
143
+ case response.code
144
+ when 400
145
+ raise Exception::BadRequest.new(method, response.effective_url, parsed_body)
146
+ when 403
147
+ raise Exception::Forbidden.new(method, response.effective_url, parsed_body)
148
+ when 404
149
+ raise Exception::NotFound.new(method, response.effective_url, parsed_body)
150
+ when 409
151
+ raise Exception::Conflict.new(method, response.effective_url, parsed_body)
152
+ else
153
+ raise Exception::ServiceError.new(method, response.effective_url, parsed_body)
154
+ end
139
155
  end
140
156
  end
141
157
 
@@ -70,5 +70,26 @@ module Grac
70
70
 
71
71
  alias_method :to_s, :message
72
72
  end
73
+
74
+ class ErrorWithInvalidContent < StandardError
75
+ def initialize(method, url, status, raw_body, expected_type)
76
+ @method = (method || "").upcase
77
+ @url = url
78
+ @status = status
79
+ @raw_body = raw_body
80
+ @expected_type = expected_type
81
+ end
82
+
83
+ def message
84
+ "#{@method} '#{@url}': Got HTTP #{@status}, failed to parse as '#{@expected_type}'. " \
85
+ "Raw Body: '#{@raw_body}'"
86
+ end
87
+
88
+ def inspect
89
+ "#{self.class.name}: #{message}"
90
+ end
91
+
92
+ alias_method :to_s, :message
93
+ end
73
94
  end
74
95
  end
@@ -1,3 +1,3 @@
1
1
  module Grac
2
- VERSION = "2.2.2"
2
+ VERSION = "2.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grac
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schoknecht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-09 00:00:00.000000000 Z
11
+ date: 2017-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake