Skip to main content

createError()

Last updated 12/09/2022


Example One

The function first checks if the ABN (Australian Business Number) provided on the Five object is valid by calling the verifyABN function. If the ABN is invalid, the function creates an error message using the createError() of the Five object and returns it. If the ABN is valid, the function returns a success using the success() on the Five object. Overall, this function is used to verify the validity of an ABN and return an appropriate result based on the result.


createError() with message
function VerifyABN(five: Five, context: any, result: FiveError) : FiveError {
if (verifyABN(five.field.ABN) === false) {
return five.createError(result, 'Invalid ABN');
}

return five.success(result);

}

Example Two

This code is creating a new transaction using the startTransaction() on the Five object. It then checks if the transaction was started successfully by calling the isOk() on the Transaction object. If the transaction was not started successfully, it returns an error message of 'Unable to start transaction' using the createError() on the Five object.


JavaScript
createError() with existing error to propagate and an optional message
const tx = five.startTransaction();
if (tx.isOk() === false) {
return five.createError(tx, 'Unable to start transaction');
}


Example Three

This code is starting a transaction using the startTransaction() on the Five object. It then checks if the transaction was started successfully by calling the isOk() on the Transaction object. If the transaction was not started successfully, it creates an error message of 'Unable to start transaction' using the createError() on the Five object and returns it. The error message includes the reason for the failure, which in this case is unable to start transaction, and a notification to check the database configuration.


JavaScript
createError() with existing error to propagate and an optional message and notification
const tx = five.startTransaction();
if (tx.isOk() === false) {
return five.createError(tx, 'Unable to start transaction', 'Check database configuration');
}