Exception: Plaid::Errors::ResponseError
- Defined in:
- lib/plaid/errors/response_error.rb
Direct Known Subclasses
ClientError, RedirectError, ServerError, ServiceUnavailableError
Defined Under Namespace
Classes: Headers
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Class Method Summary collapse
-
.load_error_body(code, raw_body, types) ⇒ Object?
Parses a raw error response body into the type declared for its status code.
-
.subclass_for_code(code) ⇒ Class
Returns the most appropriate error class for the given code.
Instance Method Summary collapse
-
#header(name) ⇒ String?
Returns the first value of a response header, or nil when the response did not include it.
-
#initialize(msg, code:, body: nil, headers: {}) ⇒ ResponseError
constructor
A new instance of ResponseError.
- #inspect ⇒ Object
Constructor Details
#initialize(msg, code:, body: nil, headers: {}) ⇒ ResponseError
Returns a new instance of ResponseError.
69 70 71 72 73 74 |
# File 'lib/plaid/errors/response_error.rb', line 69 def initialize(msg, code:, body: nil, headers: {}) @code = code @body = body @headers = Headers.from(headers) super(msg) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
62 63 64 |
# File 'lib/plaid/errors/response_error.rb', line 62 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
62 63 64 |
# File 'lib/plaid/errors/response_error.rb', line 62 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
62 63 64 |
# File 'lib/plaid/errors/response_error.rb', line 62 def headers @headers end |
Class Method Details
.load_error_body(code, raw_body, types) ⇒ Object?
Parses a raw error response body into the type declared for its status code.
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/plaid/errors/response_error.rb', line 94 def self.load_error_body(code, raw_body, types) type = types.find { |matcher, _| matcher.is_a?(::Range) ? matcher.cover?(code) : matcher == code }&.last return nil if type.nil? || raw_body.to_s.empty? begin type.load(raw_body) rescue StandardError nil end end |
.subclass_for_code(code) ⇒ Class
Returns the most appropriate error class for the given code.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/plaid/errors/response_error.rb', line 108 def self.subclass_for_code(code) case code when 300..399 RedirectError when 401 UnauthorizedError when 403 ForbiddenError when 404 NotFoundError when 400..499 ClientError when 503 ServiceUnavailableError when 500..599 ServerError else ResponseError end end |
Instance Method Details
#header(name) ⇒ String?
Returns the first value of a response header, or nil when the response did not include it.
80 81 82 |
# File 'lib/plaid/errors/response_error.rb', line 80 def header(name) Array(headers[name]).first end |
#inspect ⇒ Object
84 85 86 |
# File 'lib/plaid/errors/response_error.rb', line 84 def inspect "#<#{self.class.name} @code=#{code} @body=#{}>" end |