mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-13 23:20:05 +00:00
chore: error needs to be more specific
This commit is contained in:
@@ -19,7 +19,7 @@ import {
|
|||||||
parseSourceCode,
|
parseSourceCode,
|
||||||
createAxiosInstance
|
createAxiosInstance
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { InvalidCsrfError } from '../types/errors/InvalidCsrfError'
|
import { InvalidSASjsCsrfError } from '../types/errors/InvalidSASjsCsrfError'
|
||||||
|
|
||||||
export interface HttpClient {
|
export interface HttpClient {
|
||||||
get<T>(
|
get<T>(
|
||||||
@@ -499,7 +499,7 @@ export class RequestClient implements HttpClient {
|
|||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e instanceof InvalidCsrfError) {
|
if (e instanceof InvalidSASjsCsrfError) {
|
||||||
// Fetching root and creating CSRF cookie
|
// Fetching root and creating CSRF cookie
|
||||||
await this.httpClient
|
await this.httpClient
|
||||||
.get('/', {
|
.get('/', {
|
||||||
@@ -623,7 +623,7 @@ export const throwIfError = (response: AxiosResponse) => {
|
|||||||
typeof response.data === 'string' &&
|
typeof response.data === 'string' &&
|
||||||
response.data.toLowerCase() === 'invalid csrf token!'
|
response.data.toLowerCase() === 'invalid csrf token!'
|
||||||
) {
|
) {
|
||||||
throw new InvalidCsrfError()
|
throw new InvalidSASjsCsrfError()
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 401:
|
case 401:
|
||||||
|
|||||||
@@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
9
src/types/errors/InvalidSASjsCsrfError.ts
Normal file
9
src/types/errors/InvalidSASjsCsrfError.ts
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user