Module: Smplkit::ManagementClient::ErrorMapping
- Defined in:
- lib/smplkit/management/client.rb
Overview
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
.call ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/smplkit/management/client.rb', line 101 def call yield rescue StandardError => e raise unless generated_api_error?(e) raise Smplkit::ConnectionError, e..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
114 115 116 117 |
# File 'lib/smplkit/management/client.rb', line 114 def generated_api_error?(err) klass_name = err.class.name.to_s klass_name.start_with?("SmplkitGeneratedClient::") && klass_name.end_with?("::ApiError") end |