1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-04 11:10:05 +00:00

chore: error needs to be more specific

This commit is contained in:
Saad Jutt
2022-08-04 05:59:39 +05:00
parent e37bb182c3
commit f58f2eba97
3 changed files with 12 additions and 12 deletions

View File

@@ -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<T>(
@@ -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:

View File

@@ -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)
}
}

View File

@@ -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)
}
}