Skip to content

Instantly share code, notes, and snippets.

@darkmavis1980
Last active April 7, 2023 12:19
Show Gist options
  • Save darkmavis1980/ced312027a913355578c84bf3ff94ead to your computer and use it in GitHub Desktop.
Save darkmavis1980/ced312027a913355578c84bf3ff94ead to your computer and use it in GitHub Desktop.
const asyncFn = () => Promise.reject(new Error("async fn error", {
cause: {
type: 'FirstErrorCause'
}
}));
const asyncManipulateResponse = (response) => Promise.resolve("manipulated response");
const tryCatchFn = async () => {
try {
const response = await asyncFn();
const manipulatedResponse = await asyncManipulateResponse(response);
return manipulatedResponse;
} catch (e) {
if (e.cause.type === 'FirstErrorCause') {
console.error("readable contextualized response error messag")
}
console.error(e);
}
};
tryCatchFn();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment