Module: Smplkit::ApiSupport::ErrorMapping
- Defined in:
- lib/smplkit/api_support.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
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/smplkit/api_support.rb', line 20 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
33 34 35 36 |
# File 'lib/smplkit/api_support.rb', line 33 def generated_api_error?(err) klass_name = err.class.name.to_s klass_name.start_with?("SmplkitGeneratedClient::") && klass_name.end_with?("::ApiError") end |