Skip to content

Commit

Permalink
feat(src content-script): parse correct responses for clues
Browse files Browse the repository at this point in the history
  • Loading branch information
cmnord committed Feb 28, 2023
1 parent a1d3b18 commit 9c09bf5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/content-script.ts
Expand Up @@ -25,12 +25,16 @@ interface Clue {
}

class NotFoundError extends Error {
constructor(message: string) {
constructor(message?: string) {
super(message);
this.name = "NotFoundError";
}
}

function isNotFoundError(error: unknown): error is NotFoundError {
return error instanceof Error && error.name === "NotFoundError";
}

const CORRECT_RESPONSE_PREFIX = '<em class="correct_response">';
const CORRECT_RESPONSE_SUFFIX = "</em>";

Expand Down Expand Up @@ -298,10 +302,11 @@ class ClueParser {
const answer = parseCorrectResponse(mouseOverDiv, `clue ${i}, ${j}`);
this.answer = answer;
} catch (error: unknown) {
if (error instanceof NotFoundError) {
if (isNotFoundError(error)) {
this.answer = "Unrevealed";
} else {
throw error;
}
throw error;
}
}
}
Expand Down

0 comments on commit 9c09bf5

Please sign in to comment.