Skip to content

Commit

Permalink
Fixed error handling when error is unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura Chan committed May 24, 2022
1 parent 1291354 commit 7f8bd9f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ export enum ErrorType {
INVALID_JS_OBJECT,
}

export function handleError(error: Error, errorType: ErrorType): void {
let messageToDisplay = '';
function isError(maybeError: Error | unknown): maybeError is Error {
return maybeError !== null && typeof maybeError === 'object';
}

export function handleError(error: Error | unknown, errorType: ErrorType): void {
let messageToDisplay = 'Something went wrong';

if (errorType === ErrorType.INVALID_JS_OBJECT) {
if (errorType === ErrorType.INVALID_JS_OBJECT && isError(error)) {
messageToDisplay = `Invalid JavaScript object: ${error.message}`;
}

Expand Down

0 comments on commit 7f8bd9f

Please sign in to comment.