createError()
Last updated 10/09/2024
Example One
The following code will return the supplied message if Saturday or Sunday are selected.
Non propagation using createError()
function SaveDeliveryDate(five: Five, context: any, result: FiveError) : FiveError {
if (five.field.DeliveryDay === 'Saturday' || five.field.DeliveryDay === 'Sunday') {
return five.createError('Delivery is unavailable for weekends');
}
return five.success(result);
}
Non propagation using createError()
function SaveDeliveryDate(five, context, result) {
if (five.field.DeliveryDay === 'Saturday' || five.field.DeliveryDay === 'Sunday') {
return five.createError('Delivery is unavailable for weekends');
}
return five.success(result);
}
Example Two
The following code will return the propagated error with an additional supplied message if the delivery details fail to save into the database.
Propagation of existing error using createError() and additonal error message
function SaveDeliveryDetails(five: Five, context: any, result: FiveError) : FiveError {
const updateResult = five.executeQuery('Update Delivery Set Day=? WHERE DeliveryKey = ?', 0, five.field.DeliveryDay, five.field.DeliveryKey);
if (updateResult.isOk() === false) {
return five.createError(updateResult, 'Failed to save delivery details');
}
return five.success(result);
}
Propagation of existing error using createError() and additional error message
function SaveDeliveryDetails(five, context, result) {
if (five.field.DeliveryDay === 'Saturday' || five.field.DeliveryDay === 'Sunday') {
return five.createError('Delivery is unavailable for weekends');
}
const updateResult = five.executeQuery('Update Delivery Set Day=? WHERE DeliveryKey = ?', 0, five.field.DeliveryDay, five.field.DeliveryKey);
if (updateResult.isOk() === false) {
return five.createError(updateResult, 'Failed to save delivery details');
}
return five.success(result);
}