Class: Lapis::Yggdrasil::Messaging::ErrorResponse
- Defined in:
- lib/lapis/yggdrasil/messaging/error_response.rb
Overview
Response to a request indicating a problem occurred.
Instance Attribute Summary collapse
-
#cause ⇒ String?
readonly
Additional information about the root of the problem.
-
#error ⇒ String
readonly
Keywords describing the problem.
-
#message ⇒ String
readonly
Brief description of the problem.
Attributes inherited from Response
Instance Method Summary collapse
-
#initialize(message) ⇒ ErrorResponse
constructor
Creates a new error response by parsing a message from the server.
-
#to_error ⇒ AuthenticationError
Creates a throwable exception from the response information.
Methods inherited from Response
Constructor Details
#initialize(message) ⇒ ErrorResponse
Creates a new error response by parsing a message from the server.
28 29 30 31 32 33 34 |
# File 'lib/lapis/yggdrasil/messaging/error_response.rb', line 28 def initialize() super() hash = JSON.parse(.body) @error = hash['error'] @message = hash['errorMessage'] @cause = hash['cause'] end |
Instance Attribute Details
#cause ⇒ String? (readonly)
Additional information about the root of the problem.
24 25 26 |
# File 'lib/lapis/yggdrasil/messaging/error_response.rb', line 24 def cause @cause end |
#error ⇒ String (readonly)
Keywords describing the problem.
15 16 17 |
# File 'lib/lapis/yggdrasil/messaging/error_response.rb', line 15 def error @error end |
#message ⇒ String (readonly)
Brief description of the problem.
19 20 21 |
# File 'lib/lapis/yggdrasil/messaging/error_response.rb', line 19 def @message end |
Instance Method Details
#to_error ⇒ AuthenticationError
Creates a throwable exception from the response information.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/lapis/yggdrasil/messaging/error_response.rb', line 38 def to_error code = case @error when 'Method Not Allowed' ErrorCodes::METHOD_NOT_ALLOWED when 'Not Found' ErrorCodes::NOT_FOUND when 'ForbiddenOperationException' if @cause == 'UserMigratedException' ErrorCodes::ACCOUNT_MIGRATED else case @message when /username/ ErrorCodes::INVALID_CREDENTIALS when /credentials/ ErrorCodes::TOO_MANY_ATTEMPTS when /token/ ErrorCodes::INVALID_TOKEN end end when 'IllegalArgumentException' case @message when /profile/ ErrorCodes::PROFILE_NOT_SUPPORTED when /credentials/ ErrorCodes::NO_CREDENTIALS end when 'Unsupported Media Type' ErrorCodes::UNSUPPORTED_MEDIA_TYPE end AuthenticationError.new(code, @message) end |