Add InvalidID error
parent
c0a9718489
commit
e04b7e2338
|
@ -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 {}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue