From e9f5cb2a6277cd4ddef87acb936cb106dce499bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20S=C3=B3jko?= Date: Wed, 21 Dec 2022 12:19:48 +0100 Subject: [PATCH] fix(api): handling expired token responses --- packages/api/src/Domain/Http/HttpService.ts | 9 ++++----- packages/api/src/Domain/Http/HttpStatusCode.ts | 1 + packages/snjs/mocha/subscriptions.test.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/api/src/Domain/Http/HttpService.ts b/packages/api/src/Domain/Http/HttpService.ts index ca873f1307c..be737188ca2 100644 --- a/packages/api/src/Domain/Http/HttpService.ts +++ b/packages/api/src/Domain/Http/HttpService.ts @@ -115,7 +115,7 @@ export class HttpService implements HttpServiceInterface { return false } - const response = (await this.post(joinPaths(this.host, Paths.v1.refreshSession), { + const response = (await this.post(Paths.v1.refreshSession, { access_token: this.session.accessToken.value, refresh_token: this.session.refreshToken.value, })) as SessionRefreshResponse @@ -265,13 +265,12 @@ export class HttpService implements HttpServiceInterface { } catch (error) { console.error(error) } - if (httpStatus >= HttpStatusCode.Success && httpStatus < HttpStatusCode.MultipleChoices) { - resolve(response) - } else { + if (httpStatus >= HttpStatusCode.Success && httpStatus < HttpStatusCode.InternalServerError) { if (httpStatus === HttpStatusCode.Forbidden && response.data && response.data.error !== undefined) { ;(response.data as HttpErrorResponseBody).error.message = ErrorMessage.RateLimited } - + resolve(response) + } else { reject(response) } } diff --git a/packages/api/src/Domain/Http/HttpStatusCode.ts b/packages/api/src/Domain/Http/HttpStatusCode.ts index 02bc6597d83..21c1815c5ad 100644 --- a/packages/api/src/Domain/Http/HttpStatusCode.ts +++ b/packages/api/src/Domain/Http/HttpStatusCode.ts @@ -7,4 +7,5 @@ export enum HttpStatusCode { Forbidden = 403, Gone = 410, ExpiredAccessToken = 498, + InternalServerError = 500, } diff --git a/packages/snjs/mocha/subscriptions.test.js b/packages/snjs/mocha/subscriptions.test.js index 4c5687a5344..a415055ded9 100644 --- a/packages/snjs/mocha/subscriptions.test.js +++ b/packages/snjs/mocha/subscriptions.test.js @@ -2,7 +2,7 @@ import * as Factory from './lib/factory.js' chai.use(chaiAsPromised) const expect = chai.expect -describe.skip('subscriptions', function () { +describe('subscriptions', function () { this.timeout(Factory.TwentySecondTimeout) let application