Skip to content

Commit

Permalink
🚀 Improve the error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniovizuete committed Oct 10, 2022
1 parent 2eaf742 commit f3744a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/Result/Result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Params = {
export default function Result({ result, error, loading }: Params) {
if (error) {
return (
<div className="overflow-auto h-full flex flex-col gap-5 p-5">
<div className="overflow-auto h-full flex flex-col gap-5 p-5 justify-start items-center">
<NonIdealState
className="w-full h-fit"
title="Error"
Expand Down
16 changes: 15 additions & 1 deletion src/lib/peform-query/perform-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,26 @@ export function performQuery({
if (this.readyState === XMLHttpRequest.DONE) {
if (this.status === 200) {
resolve(parseResponse(this.responseText));
} else if (this.status === 401) {
reject("Unauthorized");
} else if (this.status === 403) {
reject("Forbidden");
} else if (this.status === 0) {
reject("Connection error");
} else {
reject(this.responseText);
}
}
};

xhr.send(query);
xhr.onerror = function () {
reject("Network error");
};

try {
xhr.send(query);
} catch (e) {
reject((e as Error).message);
}
});
}

0 comments on commit f3744a1

Please sign in to comment.