Nov 09, 2023 04:07 AM
Hi,
I'd like to insert the error message into a field, so I used try catch with both of them updating a variable, which I then used to update the field. Weird; it only updated on success, not on error. Can anyone help?
let config = input.config();
const recordId = config.recordid;
let tabletable = config.tabletable;
let table = base.getTable(tabletable);
let query = await table.selectRecordsAsync({ fields: ["Error"] });
let err;
try {
await table.updateRecordAsync(recordId, {
"Eat": "Cheese" // no such field
})
err = "Code executed successfully";
} catch (error) {
err = error.message;
} finally {
console.log(err);
await table.updateRecordAsync(recordId, {
"Error": err
}
);
}
console.log("Updated a record!");
CONSOLE.LOG
"Could not find a field with name or ID "Eat"."
ERROR
Error: Could not find a field with name or ID "Eat".
at main on line 16
As you can see, err was properly logged. But the record was not updated.
Solved! Go to Solution.
May 21, 2024 04:04 AM
I ended up outputting the Error and then using the update field action to update the field.
Nov 09, 2023 01:25 PM
table.updateRecordAsync returns a Promise, and its error handling is different. The failure will not go to the catch block as you've written.
You should use catch as how it's used in this reply: https://community.airtable.com/t5/development-apis/error-handling-if-single-select-field-option-does...
Nov 15, 2023 12:43 PM
But it caught the err, and pushed it out to console.log. It just didn't update the error field in the table.
May 20, 2024 05:34 PM
Did you ever figure out how to update a record within the catch block? I'm running into the same issue.
May 21, 2024 04:04 AM
I ended up outputting the Error and then using the update field action to update the field.