Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): handling expired token responses #2113

Merged
merged 1 commit into from Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/api/src/Domain/Http/HttpService.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/Domain/Http/HttpStatusCode.ts
Expand Up @@ -7,4 +7,5 @@ export enum HttpStatusCode {
Forbidden = 403,
Gone = 410,
ExpiredAccessToken = 498,
InternalServerError = 500,
}
2 changes: 1 addition & 1 deletion packages/snjs/mocha/subscriptions.test.js
Expand Up @@ -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
Expand Down