frederick_api 0.3.2 → 0.4.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcd5376c71e168c4a465fea05d201c98fdeb34a8
|
4
|
+
data.tar.gz: c32d4ff431afc095213e192113857e7cf64008c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25a914b9aa9e5d2db5cb6c0fff20e7fa3ac9fd81723bfb036dd4a17beb486ea4c1a72afc1a46e2fb40c93001a86f24859110192a8bdcd79c01fa6f12870a44c0
|
7
|
+
data.tar.gz: ec3f75966e35fea113626823e6e5b8429280377ace75231a63d6ce4caf4873d3b5afe4b16426518091f80ae20463af2f1645d7c795434c065372c0efc3558935
|
data/lib/frederick_api.rb
CHANGED
@@ -7,6 +7,7 @@ require 'active_support/concern'
|
|
7
7
|
|
8
8
|
# FrederickAPI libs
|
9
9
|
require 'frederick_api/configuration'
|
10
|
+
require 'frederick_api/v2/errors/errors'
|
10
11
|
require 'frederick_api/v2/helpers/has_many'
|
11
12
|
require 'frederick_api/v2/helpers/paginator'
|
12
13
|
require 'frederick_api/v2/helpers/query_builder'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FrederickAPI
|
4
|
+
module V2
|
5
|
+
module Errors
|
6
|
+
# Base exception class for client errors (i.e. validation, bad request)
|
7
|
+
class Error < JsonApiClient::Errors::ClientError
|
8
|
+
attr_reader :errors
|
9
|
+
|
10
|
+
# Initialize with a JsonApiClient::ResultSet or a Resource
|
11
|
+
def initialize(result)
|
12
|
+
# @env is used in base class JsonApiClient::Errors::Error
|
13
|
+
@env = result
|
14
|
+
@errors = result.errors || []
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
return "Client Error: #{self.errors.first['detail']}" if self.errors.any?
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class BadRequest < Error; end
|
24
|
+
class UnprocessableEntity < Error; end
|
25
|
+
|
26
|
+
ERROR_CODES = {
|
27
|
+
'400' => BadRequest,
|
28
|
+
'422' => UnprocessableEntity
|
29
|
+
}.freeze
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -23,11 +23,20 @@ module FrederickAPI
|
|
23
23
|
|
24
24
|
# Retry once on unhandled server errors
|
25
25
|
def request(type, path, params)
|
26
|
-
super
|
26
|
+
handle_errors(super)
|
27
27
|
rescue JsonApiClient::Errors::ConnectionError, JsonApiClient::Errors::ServerError => ex
|
28
28
|
raise ex if ex.is_a?(JsonApiClient::Errors::NotFound) || ex.is_a?(JsonApiClient::Errors::Conflict)
|
29
|
-
super
|
29
|
+
handle_errors(super)
|
30
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def handle_errors(result)
|
35
|
+
return result unless result.has_errors?
|
36
|
+
error_klass = FrederickAPI::V2::Errors::ERROR_CODES[result.errors.first[:status]] ||
|
37
|
+
FrederickAPI::V2::Errors::Error
|
38
|
+
raise error_klass, result
|
39
|
+
end
|
31
40
|
end
|
32
41
|
end
|
33
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frederick_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frederick Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_api_client
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- lib/frederick_api/v2/contact_list.rb
|
42
42
|
- lib/frederick_api/v2/contact_property.rb
|
43
43
|
- lib/frederick_api/v2/contact_type.rb
|
44
|
+
- lib/frederick_api/v2/errors/errors.rb
|
44
45
|
- lib/frederick_api/v2/helpers/has_many.rb
|
45
46
|
- lib/frederick_api/v2/helpers/paginator.rb
|
46
47
|
- lib/frederick_api/v2/helpers/query_builder.rb
|