Module: Smplkit::ApiSupport::ErrorMapping Private

Defined in:
lib/smplkit/api_support.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Wraps a generated-API call and converts any ApiError raised by the generated layer into the Smplkit::Error hierarchy. Connection-level failures (no response from the server) become Smplkit::ConnectionError; status-coded failures route through Errors.raise_for_status which emits NotFoundError / ConflictError / ValidationError / Error depending on the JSON:API body.

Class Method Summary collapse

Class Method Details

.callObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/smplkit/api_support.rb', line 24

def call
  yield
rescue StandardError => e
  raise unless generated_api_error?(e)

  raise Smplkit::ConnectionError, e.message.to_s if e.code.nil? || e.code.zero?

  Smplkit::Errors.raise_for_status(e.code, e.response_body.to_s)
  # raise_for_status only returns on 2xx; if we get here the generated
  # layer raised on a 2xx (shouldn't happen) so re-raise the original.
  raise
end

.generated_api_error?(err) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/smplkit/api_support.rb', line 37

def generated_api_error?(err)
  klass_name = err.class.name.to_s
  klass_name.start_with?("SmplkitGeneratedClient::") && klass_name.end_with?("::ApiError")
end