Class: MLB::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/mlb/error_handler.rb

Constant Summary collapse

ERROR_MAP =
{
  400 => BadRequest,
  401 => Unauthorized,
  403 => Forbidden,
  404 => NotFound,
  406 => NotAcceptable,
  409 => ConnectionException,
  410 => Gone,
  413 => PayloadTooLarge,
  422 => UnprocessableEntity,
  429 => TooManyRequests,
  500 => InternalServerError,
  502 => BadGateway,
  503 => ServiceUnavailable,
  504 => GatewayTimeout
}.freeze

Instance Method Summary collapse

Instance Method Details

#handle(response:) ⇒ Object



37
38
39
40
41
# File 'lib/mlb/error_handler.rb', line 37

def handle(response:)
  raise error(response) unless response.is_a?(Net::HTTPSuccess)

  response.body
end