Skip to main content

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.

 

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-doesn-t-exist/m-p/56175/highlight/true#M3146


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-doesn-t-exist/m-p/56175/highlight/true#M3146


But it caught the err, and pushed it out to console.log. It just didn't update the error field in the table.


But it caught the err, and pushed it out to console.log. It just didn't update the error field in the table.


Did you ever figure out how to update a record within the catch block? I'm running into the same issue.


Did you ever figure out how to update a record within the catch block? I'm running into the same issue.


I ended up outputting the Error and then using the update field action to update the field.


Reply