Exception: YolodiceClient::RemoteError

Inherits:
StandardError
  • Object
show all
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

Instance Method Summary collapse

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

#codeObject

Error code, as returned from the server.



269
270
271
# File 'lib/yolodice_client.rb', line 269

def code
  @code
end

#dataObject

Optional data object, if returned by the server.



272
273
274
# File 'lib/yolodice_client.rb', line 272

def data
  @data
end