Exception: FunTranslations::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/fun_translations/error.rb

Overview

Custom errors

Constant Summary collapse

ClientError =
Class.new(self)
ServerError =
Class.new(self)
BadRequest =
Class.new(ClientError)
Unauthorized =
Class.new(ClientError)
NotAcceptable =
Class.new(ClientError)
NotFound =
Class.new(ClientError)
Conflict =
Class.new(ClientError)
TooManyRequests =
Class.new(ClientError)
Forbidden =
Class.new(ClientError)
Locked =
Class.new(ClientError)
MethodNotAllowed =
Class.new(ClientError)
NotImplemented =
Class.new(ServerError)
BadGateway =
Class.new(ServerError)
ServiceUnavailable =
Class.new(ServerError)
GatewayTimeout =
Class.new(ServerError)
ERRORS =
{
  400 => FunTranslations::Error::BadRequest,
  401 => FunTranslations::Error::Unauthorized,
  403 => FunTranslations::Error::Forbidden,
  404 => FunTranslations::Error::NotFound,
  405 => FunTranslations::Error::MethodNotAllowed,
  406 => FunTranslations::Error::NotAcceptable,
  409 => FunTranslations::Error::Conflict,
  423 => FunTranslations::Error::Locked,
  429 => FunTranslations::Error::TooManyRequests,
  500 => FunTranslations::Error::ServerError,
  502 => FunTranslations::Error::BadGateway,
  503 => FunTranslations::Error::ServiceUnavailable,
  504 => FunTranslations::Error::GatewayTimeout
}.freeze

Class Method Summary collapse

Class Method Details

.from_response(body) ⇒ Object

Create a new error from an HTTP response



42
43
44
45
# File 'lib/fun_translations/error.rb', line 42

def from_response(body)
  msg = body['detail'] || body['message']
  new msg.to_s
end