Error handling
Each database operation returns an error object in the callback function:
- On success,
nullwill be returned - On error, the error object is populated.
Error Object
Error objects are of class AerospikeError and include the following properties:
code— The operation status.message— The message corresponding to an error code. Can be an empty string if the operation completed successfully.func— The function in which the error occurred. Can be NULL if not captured properly in the operation.file— The file in which the error occurred. Can be NULL if not captured properly in the operation.line— The line number in the file in which the error occurred. Can be 0 if not captured properly in the operation.
This example handles an error from a put() operation:
try { await client.put(key, bins);} catch (error) { console.error("error: %s [%d]\n%s", error.message, error.code, error.stack); process.exit(-1);}