odata4 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/odata4.rb +1 -0
- data/lib/odata4/errors.rb +68 -0
- data/lib/odata4/service/response.rb +6 -13
- data/lib/odata4/version.rb +1 -1
- data/spec/odata4/entity_set_spec.rb +1 -1
- data/spec/odata4/errors_spec.rb +48 -0
- data/spec/odata4/service/response_spec.rb +8 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 681b21fbcc189d8fd525c14967ee0536e5175831
|
4
|
+
data.tar.gz: 0c1c00d948fbbf6da13d9474e89c68f87a32e60b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caa27586434ea04697571112c0151e5487e0212dd630e96ad6e57689ccc608a07883ba723926bbac06d6b0d0dc5efba22129389216148cb0ba31f644f8e4c15b
|
7
|
+
data.tar.gz: d7c03530c1bb69d48ef53f2fcbfd3a9085025c67c0f30200acb208734b755cc565e6f05ce8f86bc6403fde13ab028c5689d546f02562d5c2be9e34677c51bbbf
|
data/CHANGELOG.md
CHANGED
data/lib/odata4.rb
CHANGED
@@ -0,0 +1,68 @@
|
|
1
|
+
module OData4
|
2
|
+
# Base class for OData4 errors
|
3
|
+
class Error < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
# Base class for network errors
|
7
|
+
class RequestError < Error
|
8
|
+
attr_reader :response
|
9
|
+
|
10
|
+
def initialize(response, message = nil)
|
11
|
+
@message = message
|
12
|
+
@response = response
|
13
|
+
end
|
14
|
+
|
15
|
+
def http_status
|
16
|
+
response.status
|
17
|
+
end
|
18
|
+
|
19
|
+
def message
|
20
|
+
[default_message, @message].compact.join(': ')
|
21
|
+
end
|
22
|
+
|
23
|
+
def default_message
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class ClientError < RequestError
|
29
|
+
end
|
30
|
+
|
31
|
+
class ServerError < RequestError
|
32
|
+
end
|
33
|
+
|
34
|
+
module Errors
|
35
|
+
ERROR_MAP = []
|
36
|
+
|
37
|
+
CLIENT_ERRORS = {
|
38
|
+
400 => "Bad Request",
|
39
|
+
401 => "Access Denied",
|
40
|
+
403 => "Forbidden",
|
41
|
+
404 => "Not Found",
|
42
|
+
405 => "Method Not Allowed",
|
43
|
+
406 => "Not Acceptable",
|
44
|
+
413 => "Request Entity Too Large"
|
45
|
+
}
|
46
|
+
|
47
|
+
CLIENT_ERRORS.each do |code, message|
|
48
|
+
klass = Class.new(ClientError) do
|
49
|
+
send(:define_method, :default_message) { "#{code} #{message}" }
|
50
|
+
end
|
51
|
+
const_set(message.delete(' \-\''), klass)
|
52
|
+
ERROR_MAP[code] = klass
|
53
|
+
end
|
54
|
+
|
55
|
+
SERVER_ERRORS = {
|
56
|
+
500 => "Internal Server Error",
|
57
|
+
503 => "Service Unavailable"
|
58
|
+
}
|
59
|
+
|
60
|
+
SERVER_ERRORS.each do |code, message|
|
61
|
+
klass = Class.new(ServerError) do
|
62
|
+
send(:define_method, :default_message) { "#{code} #{message}" }
|
63
|
+
end
|
64
|
+
const_set(message.delete(' \-\''), klass)
|
65
|
+
ERROR_MAP[code] = klass
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -94,17 +94,10 @@ module OData4
|
|
94
94
|
# occured.
|
95
95
|
#
|
96
96
|
# @return [self]
|
97
|
-
def
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
raise "Not Found" if [0,404].include?(status)
|
102
|
-
raise "Method Not Allowed" if status == 405
|
103
|
-
raise "Not Acceptable" if status == 406
|
104
|
-
raise "Request Entity Too Large" if status == 413
|
105
|
-
raise "Internal Server Error" if status == 500
|
106
|
-
raise "Service Unavailable" if status == 503
|
107
|
-
self
|
97
|
+
def validate_response!
|
98
|
+
if error = OData4::Errors::ERROR_MAP[status]
|
99
|
+
raise error, response, error_message
|
100
|
+
end
|
108
101
|
end
|
109
102
|
|
110
103
|
private
|
@@ -117,7 +110,7 @@ module OData4
|
|
117
110
|
Body: #{response.body}
|
118
111
|
EOS
|
119
112
|
check_content_type
|
120
|
-
|
113
|
+
validate_response!
|
121
114
|
rescue Faraday::TimeoutError
|
122
115
|
logger.info "Request timed out."
|
123
116
|
@timed_out = true
|
@@ -144,7 +137,7 @@ module OData4
|
|
144
137
|
# We catch that here and bypass content type detection.
|
145
138
|
@empty = true
|
146
139
|
else
|
147
|
-
raise
|
140
|
+
raise RequestError, response, "Invalid response type '#{content_type}'"
|
148
141
|
end
|
149
142
|
end
|
150
143
|
|
data/lib/odata4/version.rb
CHANGED
@@ -101,7 +101,7 @@ describe OData4::EntitySet, vcr: {cassette_name: 'entity_set_specs'} do
|
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'raises an error when no entity was found' do
|
104
|
-
expect { nonexistant_entity }.to raise_error(
|
104
|
+
expect { nonexistant_entity }.to raise_error(OData4::Errors::NotFound)
|
105
105
|
end
|
106
106
|
|
107
107
|
describe 'eager loading' do
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData4::RequestError do
|
4
|
+
subject { OData4::RequestError.new(response, 'The server made a boo-boo.') }
|
5
|
+
let(:response) { instance_double('Faraday::Response', status: 400) }
|
6
|
+
|
7
|
+
describe '#http_status' do
|
8
|
+
it 'returns the status code' do
|
9
|
+
expect(subject.http_status).to eq(response.status)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#response' do
|
14
|
+
it 'returns the response' do
|
15
|
+
expect(subject.response).to eq(response)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#message' do
|
20
|
+
it 'returns the error message' do
|
21
|
+
expect(subject.message).to eq('The server made a boo-boo.')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe OData4::Errors::InternalServerError do
|
27
|
+
let(:response) { instance_double('Faraday::Response', status: 500) }
|
28
|
+
|
29
|
+
context 'with custom error message' do
|
30
|
+
subject { OData4::Errors::InternalServerError.new(response, 'The server made a boo-boo.')}
|
31
|
+
|
32
|
+
describe '#message' do
|
33
|
+
it 'combines default message with custom message' do
|
34
|
+
expect(subject.message).to eq('500 Internal Server Error: The server made a boo-boo.')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'without custom error message' do
|
40
|
+
subject { OData4::Errors::InternalServerError.new(response) }
|
41
|
+
|
42
|
+
describe '#message' do
|
43
|
+
it 'returns the default message' do
|
44
|
+
expect(subject.message).to eq('500 Internal Server Error')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -74,4 +74,12 @@ describe OData4::Service::Response, vcr: {cassette_name: 'service/response_specs
|
|
74
74
|
it { expect(subject).to be_success }
|
75
75
|
it { expect(subject.body).to match(/123/) }
|
76
76
|
end
|
77
|
+
|
78
|
+
context 'with unregistered content type' do
|
79
|
+
let(:content_type) { 'text/unknown' }
|
80
|
+
let(:response_status) { 200 }
|
81
|
+
let(:response_body) { '123' }
|
82
|
+
|
83
|
+
it { expect { subject }.to raise_error(OData4::RequestError) }
|
84
|
+
end
|
77
85
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odata4
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Wagner
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-05-
|
12
|
+
date: 2018-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- lib/odata4/entity.rb
|
204
204
|
- lib/odata4/entity_container.rb
|
205
205
|
- lib/odata4/entity_set.rb
|
206
|
+
- lib/odata4/errors.rb
|
206
207
|
- lib/odata4/navigation_property.rb
|
207
208
|
- lib/odata4/navigation_property/proxy.rb
|
208
209
|
- lib/odata4/properties.rb
|
@@ -277,6 +278,7 @@ files:
|
|
277
278
|
- spec/odata4/entity_container_spec.rb
|
278
279
|
- spec/odata4/entity_set_spec.rb
|
279
280
|
- spec/odata4/entity_spec.rb
|
281
|
+
- spec/odata4/errors_spec.rb
|
280
282
|
- spec/odata4/navigation_property/proxy_spec.rb
|
281
283
|
- spec/odata4/navigation_property_spec.rb
|
282
284
|
- spec/odata4/properties/binary_spec.rb
|
@@ -362,6 +364,7 @@ test_files:
|
|
362
364
|
- spec/odata4/entity_container_spec.rb
|
363
365
|
- spec/odata4/entity_set_spec.rb
|
364
366
|
- spec/odata4/entity_spec.rb
|
367
|
+
- spec/odata4/errors_spec.rb
|
365
368
|
- spec/odata4/navigation_property/proxy_spec.rb
|
366
369
|
- spec/odata4/navigation_property_spec.rb
|
367
370
|
- spec/odata4/properties/binary_spec.rb
|