Exception: YolodiceClient::RemoteError
- Inherits:
-
StandardError
- Object
- StandardError
- YolodiceClient::RemoteError
- Defined in:
- lib/yolodice_client.rb
Overview
Thrown when an error is received from the server. RemoteError
has two extra attributes: code
and data
that correspond to the values returned in the error object in server response.
Instance Attribute Summary collapse
-
#code ⇒ Object
Error code, as returned from the server.
-
#data ⇒ Object
Optional data object, if returned by the server.
Instance Method Summary collapse
-
#initialize(error_obj = {'code' => -1, 'message' => "RPC Error"}) ⇒ RemoteError
constructor
A new instance of RemoteError.
Constructor Details
#initialize(error_obj = {'code' => -1, 'message' => "RPC Error"}) ⇒ RemoteError
Returns a new instance of RemoteError.
274 275 276 277 278 279 280 281 282 |
# File 'lib/yolodice_client.rb', line 274 def initialize(error_obj = {'code' => -1, 'message' => "RPC Error"}) @code = error_obj['code'] || -1 @data = error_obj['data'] if error_obj['data'] msg = "#{@code}: #{error_obj['message']}" if @code == 422 && @data && @data.has_key?('errors') msg += ': ' + @data['errors'].to_json end super msg end |
Instance Attribute Details
#code ⇒ Object
Error code, as returned from the server.
269 270 271 |
# File 'lib/yolodice_client.rb', line 269 def code @code end |
#data ⇒ Object
Optional data object, if returned by the server.
272 273 274 |
# File 'lib/yolodice_client.rb', line 272 def data @data end |