Exception types in JavaScript source adapters are mapped to their ruby equivalent. See the ruby exception section for more details about these exception types.
Make sure you have a Rhoconnect Helpers object in your model:
var rc = require('rhoconnect_helpers');
Raise a generic RhoConnect adapter exception.
new rc.Exception(resp, 'Something went wrong!');
Raise an exception on the login procedure.
new rc.LoginException(resp, 'A login error occurred.');
Raise an exception on the logoff procedure.
new rc.LogoffException(resp, 'A logoff error occurred.');
Raise an exception indicating a timeout occurred.
new rc.ServerTimeoutException(resp, 'A timeout occurred.');
Raise an exception concerning the backend service.
new rc.ServerErrorException(resp, 'An error occurred with our systems, please try again.');
Raise a conflict exception to indicate there was a conflict in handling the record. This will trigger RhoConnect’s automatic processing for conflicts.
new rc.ObjectConflictErrorException( resp, 'A conflict error occurred, please update your copy and try again' );
The following example raises a ServerErrorException
in the delete function if the record was not successfully deleted.
this.del = function(resp){ var objId = resp.params.delete_object.id; var options = { host: host, path: '/products/' + objId + '.json', method: 'DELETE', headers: { 'Content-Type': 'application/json' } }; var req = http.request(options, function(res){ res.on('data', function(){}); res.on('end', function(){ resp.send(true); }); res.on('error', function(){ new rc.ServerErrorException(resp, 'There was an error deleting, please try again'); }); }); req.end(); };