Skip to content

Commit

Permalink
fix: better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
smorrisj committed Oct 17, 2023
1 parent 4f80247 commit d1c89b7
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions client/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,7 @@ const _run = async (selected = false, uri?: Uri) => {

await runCode(selected, uri)
.catch((err) => {
console.dir(err);
window.showErrorMessage(
err.response?.data ? JSON.stringify(err.response.data) : err.message,
);
onRunError(err);
})
.finally(() => {
running = false;
Expand Down Expand Up @@ -235,3 +232,41 @@ export async function runTask(
messageEmitter.fire(`${l10n.t("SAS code running...")}\r\n`);
return cancelled ? undefined : session.run(code);
}

const isErrorRep = (err: unknown): err is SessionError => {
if (
err &&
typeof err === "object" &&
"message" in err &&
"details" in err &&
"errorCode" in err
) {
return true;
}
return false;
};

const onRunError = (err) => {
console.dir(err);

if (err.response) {
// The request was made and we got a status code that falls out side of the 2xx range
const errorData = err.response.data;

if (isErrorRep(errorData)) {
//errorData is an error representation, extract out the details to show a better message
const details = errorData.details;
const options = {
modal: true,
detail: details.join("\n"),
};
window.showErrorMessage(errorData.message, options);
} else {
window.showErrorMessage(err.message);
}
} else {
// Either the request was made but no response was received, or
// there was an issue in the request setup itself, just show the message
window.showErrorMessage(err.message);
}
};

0 comments on commit d1c89b7

Please sign in to comment.