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 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 {
|
export class GenericAxiosError extends Error implements IBaseError {
|
||||||
id: number;
|
id: number;
|
||||||
|
@ -52,4 +55,6 @@ export class InvalidF95Token extends Error {}
|
||||||
|
|
||||||
export class UserNotLogged extends Error {}
|
export class UserNotLogged extends Error {}
|
||||||
|
|
||||||
|
export class InvalidID extends Error {}
|
||||||
|
|
||||||
export class ParameterError extends Error {}
|
export class ParameterError extends Error {}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { urls } from "../../constants/url";
|
||||||
import { fetchHTML } from "../../network-helper";
|
import { fetchHTML } from "../../network-helper";
|
||||||
import { GENERIC, MEMBER } from "../../constants/css-selector";
|
import { GENERIC, MEMBER } from "../../constants/css-selector";
|
||||||
import shared from "../../shared";
|
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";
|
import { ILazy } from "../../interfaces";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -151,7 +151,7 @@ export default class PlatformUser implements ILazy {
|
||||||
if (!shared.isLogged) throw new UserNotLogged(USER_NOT_LOGGED);
|
if (!shared.isLogged) throw new UserNotLogged(USER_NOT_LOGGED);
|
||||||
|
|
||||||
// Check ID
|
// 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
|
// Prepare the URL
|
||||||
const url = new URL(this.id.toString(), `${urls.MEMBERS}/`).toString();
|
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 { urls } from "../../constants/url";
|
||||||
import { fetchHTML } from "../../network-helper";
|
import { fetchHTML } from "../../network-helper";
|
||||||
import shared from "../../shared";
|
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";
|
import { ILazy } from "../../interfaces";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,7 +102,7 @@ export default class Post implements ILazy {
|
||||||
if (!shared.isLogged) throw new UserNotLogged(USER_NOT_LOGGED);
|
if (!shared.isLogged) throw new UserNotLogged(USER_NOT_LOGGED);
|
||||||
|
|
||||||
// Check ID
|
// 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
|
// Fetch HTML page containing the post
|
||||||
const url = new URL(this.id.toString(), urls.POSTS).toString();
|
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 { POST, THREAD } from "../../constants/css-selector";
|
||||||
import { fetchHTML, fetchPOSTResponse } from "../../network-helper";
|
import { fetchHTML, fetchPOSTResponse } from "../../network-helper";
|
||||||
import Shared from "../../shared";
|
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 { getJSONLD, TJsonLD } from "../../scrape-data/json-ld";
|
||||||
import shared from "../../shared";
|
import shared from "../../shared";
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ export default class Thread implements ILazy {
|
||||||
if (!shared.isLogged) throw new UserNotLogged(USER_NOT_LOGGED);
|
if (!shared.isLogged) throw new UserNotLogged(USER_NOT_LOGGED);
|
||||||
|
|
||||||
// Check ID
|
// 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
|
// Prepare the url
|
||||||
this._url = new URL(this.id.toString(), urls.THREADS).toString();
|
this._url = new URL(this.id.toString(), urls.THREADS).toString();
|
||||||
|
|
Loading…
Reference in New Issue