Exception: MangoPay::ResponseError
- Defined in:
- lib/mangopay/errors.rb
Overview
See docs.mangopay.com/api-references/response-codes-rules/ and docs.mangopay.com/api-references/error-codes/
Thrown from any MangoPay API call whenever it returns response with HTTP code != 200. Check @details hash for further info.
Two example exceptions with details:
#<MangoPay::ResponseError:
One or several required parameters are missing or incorrect. [...]
Email: The Email field is required.>
or several required parameters are missing or incorrect.
An incorrect resource ID also raises this kind of error.",
"Type"=>"param_error",
"Id"=>"66936e92-3f21-4a35-b6cf-f1d17c2fb6e5",
"Date"=>1409047252.0,
"errors"=>{"Email"=>"The Email field is required.",
"Code"=>"400",
"Url"=>"/v2/sdk-unit-tests/users/natural"}
#<MangoPay::ResponseError: Internal Server Error> {“Message”=>“Internal Server Error”,
"Type"=>"other",
"Id"=>"7bdc5c6f-2000-4cd3-96f3-2a3fcb746f07",
"Date"=>1409047251.0,
"errors"=>nil,
"Code"=>"500",
"Url"=>"/v2/sdk-unit-tests/payins/3380640/refunds"}
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#request_url ⇒ Object
readonly
Returns the value of attribute request_url.
Instance Method Summary collapse
- #error ⇒ Object
- #errors ⇒ Object
-
#initialize(request_url, code, details) ⇒ ResponseError
constructor
A new instance of ResponseError.
- #message ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(request_url, code, details) ⇒ ResponseError
Returns a new instance of ResponseError.
42 43 44 45 46 47 48 49 |
# File 'lib/mangopay/errors.rb', line 42 def initialize(request_url, code, details) @request_url, @code, @details = request_url, code, details @details['Code'] = code @details['Url'] = request_url.request_uri super() if end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
40 41 42 |
# File 'lib/mangopay/errors.rb', line 40 def code @code end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
40 41 42 |
# File 'lib/mangopay/errors.rb', line 40 def details @details end |
#request_url ⇒ Object (readonly)
Returns the value of attribute request_url.
40 41 42 |
# File 'lib/mangopay/errors.rb', line 40 def request_url @request_url end |
Instance Method Details
#error ⇒ Object
52 |
# File 'lib/mangopay/errors.rb', line 52 def error; @details['error']; end |
#errors ⇒ Object
53 |
# File 'lib/mangopay/errors.rb', line 53 def errors; @details['errors'] || error; end |
#message ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/mangopay/errors.rb', line 55 def ; if error msg = error else msg = @details['Message'] || @details['message'] msg += errors.sort.map {|k,v| " #{k}: #{v}"}.join if (errors && errors.is_a?(Hash)) msg end end |
#type ⇒ Object
51 |
# File 'lib/mangopay/errors.rb', line 51 def type; @details['Type'] || @details['type']; end |