From f58f2eba975b72fbd47b9547c4ecd982fb4340bc Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Thu, 4 Aug 2022 05:59:39 +0500 Subject: [PATCH] chore: error needs to be more specific --- src/request/RequestClient.ts | 6 +++--- src/types/errors/InvalidCsrfError.ts | 9 --------- src/types/errors/InvalidSASjsCsrfError.ts | 9 +++++++++ 3 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 src/types/errors/InvalidCsrfError.ts create mode 100644 src/types/errors/InvalidSASjsCsrfError.ts diff --git a/src/request/RequestClient.ts b/src/request/RequestClient.ts index c1753ba..3ab2b83 100644 --- a/src/request/RequestClient.ts +++ b/src/request/RequestClient.ts @@ -19,7 +19,7 @@ import { parseSourceCode, createAxiosInstance } from '../utils' -import { InvalidCsrfError } from '../types/errors/InvalidCsrfError' +import { InvalidSASjsCsrfError } from '../types/errors/InvalidSASjsCsrfError' export interface HttpClient { get( @@ -499,7 +499,7 @@ export class RequestClient implements HttpClient { throw e } - if (e instanceof InvalidCsrfError) { + if (e instanceof InvalidSASjsCsrfError) { // Fetching root and creating CSRF cookie await this.httpClient .get('/', { @@ -623,7 +623,7 @@ export const throwIfError = (response: AxiosResponse) => { typeof response.data === 'string' && response.data.toLowerCase() === 'invalid csrf token!' ) { - throw new InvalidCsrfError() + throw new InvalidSASjsCsrfError() } break case 401: diff --git a/src/types/errors/InvalidCsrfError.ts b/src/types/errors/InvalidCsrfError.ts deleted file mode 100644 index cf174ab..0000000 --- a/src/types/errors/InvalidCsrfError.ts +++ /dev/null @@ -1,9 +0,0 @@ -export class InvalidCsrfError extends Error { - constructor() { - const message = 'Invalid CSRF token!' - - super(`Auth error: ${message}`) - this.name = 'InvalidCsrfError' - Object.setPrototypeOf(this, InvalidCsrfError.prototype) - } -} diff --git a/src/types/errors/InvalidSASjsCsrfError.ts b/src/types/errors/InvalidSASjsCsrfError.ts new file mode 100644 index 0000000..d785795 --- /dev/null +++ b/src/types/errors/InvalidSASjsCsrfError.ts @@ -0,0 +1,9 @@ +export class InvalidSASjsCsrfError extends Error { + constructor() { + const message = 'Invalid CSRF token!' + + super(`Auth error: ${message}`) + this.name = 'InvalidSASjsCsrfError' + Object.setPrototypeOf(this, InvalidSASjsCsrfError.prototype) + } +}