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

fix(auth): auto submit auth form if needed

This commit is contained in:
Krishna Acondy
2021-02-08 19:07:37 +00:00
parent 70d3e25c7f
commit 1b251f1cea
2 changed files with 26 additions and 5 deletions

View File

@@ -332,9 +332,13 @@ export class RequestClient implements HttpClient {
private handleError = async (e: any, callback: any) => {
const response = e.response as AxiosResponse
if (e instanceof AuthorizeError) {
const res = await this.get(e.confirmUrl, undefined, 'text/plain')
if (isAuthorizeFormRequired(res.result as string)) {
await this.authorize(res.result as string)
const res = await this.httpClient.get(e.confirmUrl, {
responseType: 'text',
headers: { 'Content-Type': 'text/plain', Accept: '*/*' }
})
if (isAuthorizeFormRequired(res?.data as string)) {
await this.authorize(res.data as string)
}
return await callback()
}
@@ -386,6 +390,16 @@ const throwIfError = (response: AxiosResponse) => {
throw new LoginRequiredError()
}
if (
typeof response.data === 'string' &&
isAuthorizeFormRequired(response.data)
) {
throw new AuthorizeError(
'Authorization required',
response.request.responseURL
)
}
if (
typeof response.data === 'string' &&
isLogInRequired(response.data) &&