Module: MixinBot::Client::ErrorMapper
- Defined in:
- lib/mixin_bot/client/error_mapper.rb
Overview
Maps Mixin API error objects to Ruby exceptions.
Class Method Summary collapse
Class Method Details
.raise_for!(verb:, path:, body:, response:, result:) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mixin_bot/client/error_mapper.rb', line 11 def raise_for!(verb:, path:, body:, response:, result:) err = result['error'] || {} code = err['code'] desc = err['description'] req_id = response&.headers&.[]('X-Request-Id') srv_time = response&.headers&.[]('X-Server-Time') errmsg = "#{verb.upcase} | #{path} | #{body}, errcode: #{code}, errmsg: #{desc}, request_id: #{req_id}, server_time: #{srv_time}" case code when 401, 20_121 raise UnauthorizedError, errmsg when 403, 20_116, 10_002, 429 raise ForbiddenError, errmsg when 404 raise NotFoundError, errmsg when 20_117 raise InsufficientBalanceError, errmsg when 20_118, 20_119 raise PinError, errmsg when 30_103 raise InsufficientPoolError, errmsg when 10_404 raise UserNotFoundError, errmsg else raise ResponseError, errmsg end end |