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.



235
236
237
238
239
240
241
242
243
# File 'lib/yolodice_client.rb', line 235

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.



230
231
232
# File 'lib/yolodice_client.rb', line 230

def code
  @code
end

#dataObject

Optional data object, if returned by the server.



233
234
235
# File 'lib/yolodice_client.rb', line 233

def data
  @data
end