Sha256: c853432a9cb2ed6e98c7a0bdfb6641074f117e160ac86178291243da073f2e38
Contents?: true
Size: 1.6 KB
Versions: 2
Compression:
Stored size: 1.6 KB
Contents
# frozen_string_literal: true module FunTranslations # Custom errors class Error < StandardError 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 << self # Create a new error from an HTTP response def from_response(body) msg = body['detail'] || body['message'] new msg.to_s end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fun_translations-0.0.1 | lib/fun_translations/error.rb |
fun_translations-0.0.1.rc1 | lib/fun_translations/error.rb |