From e79089b880f616c11c17bd0e190688ead4dcb8fd Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Fri, 28 May 2021 08:52:00 +0100 Subject: [PATCH] fix(sas9-support): throw error with invalid credentials --- src/request/RequestClient.ts | 5 +++++ src/types/errors/SAS9AuthError.ts | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/types/errors/SAS9AuthError.ts diff --git a/src/request/RequestClient.ts b/src/request/RequestClient.ts index 991b7a3..62a144e 100644 --- a/src/request/RequestClient.ts +++ b/src/request/RequestClient.ts @@ -10,6 +10,7 @@ import { } from '../types/errors' import { parseWeboutResponse } from '../utils/parseWeboutResponse' import { prefixMessage } from '@sasjs/utils/error' +import { SAS9AuthError } from '../types/errors/SAS9AuthError' export interface HttpClient { get( @@ -470,6 +471,10 @@ export const throwIfError = (response: AxiosResponse) => { throw new AuthorizeError(response.data.message, authorizeRequestUrl) } + if (response.config?.url?.includes('sasAuthError')) { + throw new SAS9AuthError() + } + const error = parseError(response.data as string) if (error) { diff --git a/src/types/errors/SAS9AuthError.ts b/src/types/errors/SAS9AuthError.ts new file mode 100644 index 0000000..2e3ad00 --- /dev/null +++ b/src/types/errors/SAS9AuthError.ts @@ -0,0 +1,9 @@ +export class SAS9AuthError extends Error { + constructor() { + super( + 'The credentials you provided cannot be authenticated. Please provide a valid set of credentials.' + ) + this.name = 'AuthorizeError' + Object.setPrototypeOf(this, SAS9AuthError.prototype) + } +}