dor-services-client 9.0.0 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6420f39cd3b4f4d1e125929725e7a749fdef2b4a3b41008fd6d6d440708aaba8
4
- data.tar.gz: 3690b2a21d44ad9cc830a04f58117731bc4ab53f5d495edc5c4a0846150cd737
3
+ metadata.gz: a4b8ec2c059acbd588a6d64e931035f5552b16bacf9d0e6a1f0b8194fb371bb2
4
+ data.tar.gz: 750be3e2a2a234299c63ee1aeb6b40c4a0a87116785cf085bc359d80676465da
5
5
  SHA512:
6
- metadata.gz: 1130a9e3510b4db1a1d383647de3e9c3c87f8b426c40586326ff88c300bb7508749c29eab8fcc35c5cb91db1cc0458fbc3b1949f12004bc3a4fa2cad9109db68
7
- data.tar.gz: 63459db88fccc089c36c02b8a6496988edfa628844b04eb8991563c3fce014c88def669b5f452f48144a1e4c0bd87b2172bb1c674567295b31b280924f86124f
6
+ metadata.gz: d0ffa417486e6136c276b2aa289d4f17e01a798ea288e727ce5b2955b722934ce7b992318ff3c88e3060a57a7cfd2a203b29d0302c6862d79cce80e6f4bab1d9
7
+ data.tar.gz: f707910e959af48ab45e29a4328217517b42c50f49314ff14e142afed33688d842b2ecfc9df8ea740e59914c31cbbd4d5b5dbff67cbb7b6e1b64e197a7aa1618
data/.rubocop.yml CHANGED
@@ -15,6 +15,9 @@ Metrics/BlockLength:
15
15
  RSpec/MultipleMemoizedHelpers:
16
16
  Max: 10
17
17
 
18
+ RSpec/ExampleLength:
19
+ Max: 10
20
+
18
21
  Gemspec/DateAssignment: # (new in 1.10)
19
22
  Enabled: true
20
23
  Layout/SpaceBeforeBrackets: # (new in 1.7)
data/.rubocop_todo.yml CHANGED
@@ -25,12 +25,6 @@ RSpec/AnyInstance:
25
25
  - 'spec/dor/services/client/metadata_spec.rb'
26
26
  - 'spec/dor/services/client/object_version_spec.rb'
27
27
 
28
- # Offense count: 1
29
- # Configuration parameters: Max, CountAsOne.
30
- RSpec/ExampleLength:
31
- Exclude:
32
- - 'spec/dor/services/client/metadata_spec.rb'
33
-
34
28
  # Offense count: 6
35
29
  RSpec/IdenticalEqualityAssertion:
36
30
  Exclude:
@@ -20,9 +20,9 @@ module Dor
20
20
 
21
21
  # This method needs its own exception handling logic due to how the endpoint service (SearchWorks) operates
22
22
  # raise a NotFoundResponse because the resource being requested was not found in the ILS (via dor-services-app)
23
- raise NotFoundResponse, ResponseErrorFormatter.format(response: resp) if resp.success? && resp.body.blank?
23
+ raise NotFoundResponse.new(response: resp) if resp.success? && resp.body.blank?
24
24
 
25
- raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp)
25
+ raise UnexpectedResponse.new(response: resp)
26
26
  end
27
27
 
28
28
  # Gets MARCXML corresponding to a barcode or catkey
@@ -45,9 +45,9 @@ module Dor
45
45
  # DOR Services App does not respond with a 404 when no match in Symphony.
46
46
  # Rather, it responds with a 500 containing "Record not found in Symphony" in the body.
47
47
  # raise a NotFoundResponse because the resource being requested was not found in the ILS (via dor-services-app)
48
- raise NotFoundResponse, ResponseErrorFormatter.format(response: resp) if !resp.success? && resp.body.match?(/Record not found in Symphony/)
48
+ raise NotFoundResponse.new(response: resp) if !resp.success? && resp.body.match?(/Record not found in Symphony/)
49
49
 
50
- raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp) unless resp.success?
50
+ raise UnexpectedResponse.new(response: resp) unless resp.success?
51
51
 
52
52
  resp.body
53
53
  end
@@ -35,7 +35,7 @@ module Dor
35
35
  # rubocop:disable Metrics/AbcSize
36
36
  def update(params:, skip_lock: false)
37
37
  # Raised if Cocina::Models::*WithMetadata not provided.
38
- raise BadRequestError, 'ETag not provided.' unless skip_lock || params.respond_to?(:lock)
38
+ raise ArgumentError, 'ETag not provided.' unless skip_lock || params.respond_to?(:lock)
39
39
 
40
40
  resp = connection.patch do |req|
41
41
  req.url object_path
@@ -3,7 +3,7 @@
3
3
  module Dor
4
4
  module Services
5
5
  class Client
6
- VERSION = '9.0.0'
6
+ VERSION = '9.1.0'
7
7
  end
8
8
  end
9
9
  end
@@ -5,6 +5,14 @@ module Dor
5
5
  class Client
6
6
  # @abstract API calls to a versioned endpoint
7
7
  class VersionedService
8
+ EXCEPTION_CLASS = {
9
+ 400 => BadRequestError,
10
+ 401 => UnauthorizedResponse,
11
+ 404 => NotFoundResponse,
12
+ 409 => ConflictResponse,
13
+ 412 => PreconditionFailedResponse
14
+ }.freeze
15
+
8
16
  def initialize(connection:, version:)
9
17
  @connection = connection
10
18
  @api_version = version
@@ -19,26 +27,17 @@ module Dor
19
27
 
20
28
  attr_reader :connection, :api_version
21
29
 
22
- # rubocop:disable Metrics/MethodLength
23
30
  def raise_exception_based_on_response!(response, object_identifier = nil)
24
- exception_class = case response.status
25
- when 400
26
- BadRequestError
27
- when 401
28
- UnauthorizedResponse
29
- when 404
30
- NotFoundResponse
31
- when 409
32
- ConflictResponse
33
- when 412
34
- PreconditionFailedResponse
35
- else
36
- UnexpectedResponse
37
- end
38
- raise exception_class,
39
- ResponseErrorFormatter.format(response: response, object_identifier: object_identifier)
31
+ data = if response.headers['content-type'] == 'application/json'
32
+ JSON.parse(response.body)
33
+ else
34
+ {}
35
+ end
36
+ exception_class = EXCEPTION_CLASS.fetch(response.status, UnexpectedResponse)
37
+ raise exception_class.new(response: response,
38
+ object_identifier: object_identifier,
39
+ errors: data.fetch('errors', []))
40
40
  end
41
- # rubocop:enable Metrics/MethodLength
42
41
 
43
42
  def build_cocina_from_response(response)
44
43
  cocina_object = Cocina::Models.build(JSON.parse(response.body))
@@ -38,7 +38,26 @@ module Dor
38
38
 
39
39
  # Error that is raised when the remote server returns some unexpected response
40
40
  # this could be any 4xx or 5xx status (except the ones that are direct children of the Error class above)
41
- class UnexpectedResponse < Error; end
41
+ class UnexpectedResponse < Error
42
+ # @param [Faraday::Response] response
43
+ # @param [String] object_identifier (nil)
44
+ # @param [Hash<String,Object>] errors (nil) the JSON-API errors object
45
+ # rubocop:disable Lint/MissingSuper
46
+ def initialize(response:, object_identifier: nil, errors: nil)
47
+ @response = response
48
+ @object_identifier = object_identifier
49
+ @errors = errors
50
+ end
51
+ # rubocop:enable Lint/MissingSuper
52
+
53
+ attr_accessor :errors
54
+
55
+ def to_s
56
+ return errors.map { |e| "#{e['title']} (#{e['detail']})" }.join(', ') if errors.present?
57
+
58
+ ResponseErrorFormatter.format(response: @response, object_identifier: @object_identifier)
59
+ end
60
+ end
42
61
 
43
62
  # Error that is raised when the remote server returns a 401 Unauthorized
44
63
  class UnauthorizedResponse < UnexpectedResponse; end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dor-services-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.0.0
4
+ version: 9.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
8
  - Michael Giarlo
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
12
  date: 2022-04-20 00:00:00.000000000 Z
@@ -213,7 +213,7 @@ dependencies:
213
213
  - - ">="
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
- description:
216
+ description:
217
217
  email:
218
218
  - jcoyne@justincoyne.com
219
219
  - leftwing@alumni.rutgers.edu
@@ -262,7 +262,7 @@ homepage: https://github.com/sul-dlss/dor-services-client
262
262
  licenses: []
263
263
  metadata:
264
264
  rubygems_mfa_required: 'true'
265
- post_install_message:
265
+ post_install_message:
266
266
  rdoc_options: []
267
267
  require_paths:
268
268
  - lib
@@ -280,8 +280,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
280
280
  - !ruby/object:Gem::Version
281
281
  version: '0'
282
282
  requirements: []
283
- rubygems_version: 3.1.4
284
- signing_key:
283
+ rubygems_version: 3.3.7
284
+ signing_key:
285
285
  specification_version: 4
286
286
  summary: A client for dor-services-app
287
287
  test_files: []