Module: MixinBot::Client::ErrorMapper
- Defined in:
- lib/mixin_bot/client/error_mapper.rb
Overview
Maps Mixin API error objects to Ruby exceptions.
Constant Summary collapse
- CODE_MAP =
{ 400 => ValidationError, 401 => UnauthorizedError, 403 => ForbiddenError, 404 => NotFoundError, 429 => RateLimitError, 10_002 => ValidationError, 10_006 => AppUpdateRequiredError, 10_104 => TransientError, 10_105 => TransientError, 10_404 => UserNotFoundError, 20_116 => ConflictError, 20_117 => InsufficientBalanceError, 20_118 => PinError, 20_119 => PinError, 20_120 => TransferError, 20_121 => UnauthorizedError, 20_123 => ConflictError, 20_124 => InsufficientBalanceError, 20_125 => ConflictError, 20_127 => TransferError, 20_131 => ValidationError, 20_133 => ConflictError, 20_134 => TransferError, 20_135 => TransferError, 20_150 => ValidationError, 30_102 => InvalidAddressFormatError, 30_103 => InsufficientPoolError, 500 => ServerError, 7000 => ServerError, 7001 => ServerError }.freeze
Class Method Summary collapse
- .build(klass, verb:, path:, body:, response:, result:) ⇒ Object
- .default_class_for_code(_code) ⇒ Object
- .raise_for!(verb:, path:, body:, response:, result:) ⇒ Object
Class Method Details
.build(klass, verb:, path:, body:, response:, result:) ⇒ Object
51 52 53 |
# File 'lib/mixin_bot/client/error_mapper.rb', line 51 def build(klass, verb:, path:, body:, response:, result:, **) APIError.build(klass, verb:, path:, body:, response:, result:, **) end |
.default_class_for_code(_code) ⇒ Object
55 56 57 |
# File 'lib/mixin_bot/client/error_mapper.rb', line 55 def default_class_for_code(_code) ResponseError end |
.raise_for!(verb:, path:, body:, response:, result:) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/mixin_bot/client/error_mapper.rb', line 44 def raise_for!(verb:, path:, body:, response:, result:) err = result['error'] || {} code = err['code']&.to_i klass = CODE_MAP[code] || default_class_for_code(code) raise APIError.build(klass, verb:, path:, body:, response:, result:) end |