Instead of using a traditional try/catch
to manage errors when initiating requests like the example below:
let body;
try {
const response = await sendRequest(
"POST",
"/api/AccountApi/RefundGetStatus",
JSON.stringify(refundParams),
undefined,
headers
);
body = response.body;
} catch (error) {
log("error", "An error occurred sending a request", { error });
throw createError("An error has occurred", DefaultErrors.API_ERROR);
}
I am considering if it is feasible to achieve the same outcome by adjusting the way error handling is done as shown here:
const response = await sendRequest(
"POST",
"/api/AccountApi/RefundGetStatus",
JSON.stringify(refundParams),
undefined,
headers
).catch((err: any) => {
log("error", "An error occurred sending a request", { err });
throw createError("An error has occurred", DefaultErrors.API_ERROR);
});
Would this code snippet above be capable of managing undefined errors and potentially JSON.parse
errors?