punn
punn2y ago

Error Tracking

Is there a way to wrap all actions to perform another action (i.e. send a slack message) when errors are thrown?
3 Replies
nipunn
nipunn2y ago
I suspect you could write a middleware pattern that does a try-catch.
punn
punnOP2y ago
Could you provide a pseudocode example?
Michal Srb
Michal Srb2y ago
Here's one way you could do this:
export const doSomething = action(async ({...}, {...}) => {
await logErrors(async () => {

})
})

async function logErrors(fn) {
try {
return await fn();
} catch (error) {
// ... do something with error

throw error;
}
}
export const doSomething = action(async ({...}, {...}) => {
await logErrors(async () => {

})
})

async function logErrors(fn) {
try {
return await fn();
} catch (error) {
// ... do something with error

throw error;
}
}

Did you find this page helpful?