Module: Pinterest::Errors
- Defined in:
- lib/pinterest/errors.rb
Overview
A list of errors returned by the client.
Defined Under Namespace
Classes: AuthorizationError, BadRequestError, BaseError, MethodNotAllowedError, NotFoundError, NotImplementedError, PermissionsError, RateLimitError, ServerError, TimeoutError
Constant Summary
- CODES =
A dictionary that associates HTTP status codes to error classes.
{ 400 => "BadRequestError", 401 => "AuthorizationError", 403 => "PermissionsError", 404 => "NotFoundError", 405 => "MethodNotAllowedError", 408 => "TimeoutError", 429 => "RateLimitError", 501 => "NotImplementedError" }.freeze
Class Method Summary collapse
-
.class_for_code(status) ⇒ Class
Get the class for a HTTP status code.
-
.create(response) ⇒ BaseError
Creates a new error.
Class Method Details
.class_for_code(status) ⇒ Class
Get the class for a HTTP status code.
89 90 91 92 |
# File 'lib/pinterest/errors.rb', line 89 def self.class_for_code(status) klass = ::Pinterest::Errors::CODES.fetch(status, "ServerError") Object.const_get("::Pinterest::Errors::#{klass}") end |
.create(response) ⇒ BaseError
Creates a new error.
78 79 80 81 82 83 |
# File 'lib/pinterest/errors.rb', line 78 def self.create(response) status = response.status = response.body["error"] || response.body["message"] class_for_code(status).new(status, , response.env) end |