From e04b7e23387bd3d91613e654bf8149f6962d2fa9 Mon Sep 17 00:00:00 2001 From: MillenniumEarl Date: Wed, 10 Mar 2021 11:35:22 +0100 Subject: [PATCH] Add InvalidID error --- src/scripts/classes/errors.ts | 5 +++++ src/scripts/classes/mapping/platform-user.ts | 4 ++-- src/scripts/classes/mapping/post.ts | 4 ++-- src/scripts/classes/mapping/thread.ts | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/scripts/classes/errors.ts b/src/scripts/classes/errors.ts index 5fcd304..aa967d0 100644 --- a/src/scripts/classes/errors.ts +++ b/src/scripts/classes/errors.ts @@ -21,6 +21,9 @@ interface IBaseError { } export const USER_NOT_LOGGED = "User not authenticated, unable to continue"; +export const INVALID_USER_ID = "Invalid user ID"; +export const INVALID_POST_ID = "Invalid post ID"; +export const INVALID_THREAD_ID = "Invalid thread ID"; export class GenericAxiosError extends Error implements IBaseError { id: number; @@ -52,4 +55,6 @@ export class InvalidF95Token extends Error {} export class UserNotLogged extends Error {} +export class InvalidID extends Error {} + export class ParameterError extends Error {} diff --git a/src/scripts/classes/mapping/platform-user.ts b/src/scripts/classes/mapping/platform-user.ts index b6ebd90..3e2d127 100644 --- a/src/scripts/classes/mapping/platform-user.ts +++ b/src/scripts/classes/mapping/platform-user.ts @@ -14,7 +14,7 @@ import { urls } from "../../constants/url"; import { fetchHTML } from "../../network-helper"; import { GENERIC, MEMBER } from "../../constants/css-selector"; import shared from "../../shared"; -import { UserNotLogged, USER_NOT_LOGGED } from "../errors"; +import { InvalidID, INVALID_USER_ID, UserNotLogged, USER_NOT_LOGGED } from "../errors"; import { ILazy } from "../../interfaces"; /** @@ -151,7 +151,7 @@ export default class PlatformUser implements ILazy { if (!shared.isLogged) throw new UserNotLogged(USER_NOT_LOGGED); // Check ID - if (!this.id && this.id < 1) throw new Error("Invalid user ID"); + if (!this.id && this.id < 1) throw new InvalidID(INVALID_USER_ID); // Prepare the URL const url = new URL(this.id.toString(), `${urls.MEMBERS}/`).toString(); diff --git a/src/scripts/classes/mapping/post.ts b/src/scripts/classes/mapping/post.ts index c8f9da5..57b992b 100644 --- a/src/scripts/classes/mapping/post.ts +++ b/src/scripts/classes/mapping/post.ts @@ -15,7 +15,7 @@ import { POST, THREAD } from "../../constants/css-selector"; import { urls } from "../../constants/url"; import { fetchHTML } from "../../network-helper"; import shared from "../../shared"; -import { UserNotLogged, USER_NOT_LOGGED } from "../errors"; +import { InvalidID, INVALID_POST_ID, UserNotLogged, USER_NOT_LOGGED } from "../errors"; import { ILazy } from "../../interfaces"; /** @@ -102,7 +102,7 @@ export default class Post implements ILazy { if (!shared.isLogged) throw new UserNotLogged(USER_NOT_LOGGED); // Check ID - if (!this.id && this.id < 1) throw new Error("Invalid post ID"); + if (!this.id && this.id < 1) throw new InvalidID(INVALID_POST_ID); // Fetch HTML page containing the post const url = new URL(this.id.toString(), urls.POSTS).toString(); diff --git a/src/scripts/classes/mapping/thread.ts b/src/scripts/classes/mapping/thread.ts index e061a1f..f391896 100644 --- a/src/scripts/classes/mapping/thread.ts +++ b/src/scripts/classes/mapping/thread.ts @@ -17,7 +17,7 @@ import { urls } from "../../constants/url"; import { POST, THREAD } from "../../constants/css-selector"; import { fetchHTML, fetchPOSTResponse } from "../../network-helper"; import Shared from "../../shared"; -import { ParameterError, UserNotLogged, USER_NOT_LOGGED } from "../errors"; +import { InvalidID, INVALID_THREAD_ID, ParameterError, UserNotLogged, USER_NOT_LOGGED } from "../errors"; import { getJSONLD, TJsonLD } from "../../scrape-data/json-ld"; import shared from "../../shared"; @@ -231,7 +231,7 @@ export default class Thread implements ILazy { if (!shared.isLogged) throw new UserNotLogged(USER_NOT_LOGGED); // Check ID - if (!this.id && this.id < 1) throw new Error("Invalid thread ID"); + if (!this.id && this.id < 1) throw new InvalidID(INVALID_THREAD_ID); // Prepare the url this._url = new URL(this.id.toString(), urls.THREADS).toString();