From 1cbf933fda3ac0d8d09d8bdb4a9649aeb817996d Mon Sep 17 00:00:00 2001 From: Mo Date: Mon, 9 Sep 2024 09:51:51 -0500 Subject: [PATCH] Prompt for reauth in case of 498 drop (#2883) --- packages/snjs/lib/Services/Api/ApiService.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/snjs/lib/Services/Api/ApiService.ts b/packages/snjs/lib/Services/Api/ApiService.ts index 103c8a123..18d4533ce 100644 --- a/packages/snjs/lib/Services/Api/ApiService.ts +++ b/packages/snjs/lib/Services/Api/ApiService.ts @@ -945,7 +945,17 @@ export class LegacyApiService } private preprocessAuthenticatedErrorResponse(response: HttpResponse) { - if (response.status === HttpStatusCode.Unauthorized && this.session) { + if (!this.session) { + return + } + + /** + * In most cases the ExpiredAccessToken erorr shouldn't reach this function, since if a 498 is caught, a refresh + * will automatically take place. However there does appear to be rare cases where for some reason the 498 falls through, + * perhaps because for example the server responds to a refresh request with a 498. In those cases, we'll just + * fallback here to the invalid session observer so that the user can be reprompted for auth. + */ + if (response.status === HttpStatusCode.Unauthorized || response.status === HttpStatusCode.ExpiredAccessToken) { this.invalidSessionObserver?.(response.data.error?.tag === ErrorTag.RevokedSession) } }