Skip to content

Commit e7dfa65

Browse files
authored
Merge pull request #2824 from ORCID/lmendoza/PD-0000hot-fix-switch-user-issues
PD-5489
2 parents f909035 + 10198da commit e7dfa65

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/app/core/http/retry-transient.interceptor.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
import { Injectable } from '@angular/core'
99
import { Observable, timer } from 'rxjs'
1010
import { retry } from 'rxjs/operators'
11+
import { SKIP_TRANSIENT_RETRY } from './retry-transient'
1112

1213
const RETRYABLE_HTTP_STATUSES = new Set([0, 408, 502, 503, 504])
13-
const RETRYABLE_HTTP_METHODS = new Set(['GET', 'HEAD', 'OPTIONS'])
1414
const MAX_RETRIES = 2
1515

1616
@Injectable()
@@ -19,9 +19,8 @@ export class RetryTransientInterceptor implements HttpInterceptor {
1919
req: HttpRequest<unknown>,
2020
next: HttpHandler
2121
): Observable<HttpEvent<unknown>> {
22-
// Retrying non-idempotent requests (e.g. switch-user POST) can trigger
23-
// duplicate server-side actions and break account/session flows.
24-
if (!RETRYABLE_HTTP_METHODS.has(req.method.toUpperCase())) {
22+
// Allow request-level opt out for known special flows.
23+
if (req.context.get(SKIP_TRANSIENT_RETRY)) {
2524
return next.handle(req)
2625
}
2726

src/app/core/http/retry-transient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { HttpErrorResponse } from '@angular/common/http'
1+
import { HttpContextToken, HttpErrorResponse } from '@angular/common/http'
22
import { MonoTypeOperatorFunction, timer } from 'rxjs'
33
import { retry } from 'rxjs/operators'
44

55
export const RETRYABLE_HTTP_STATUSES = new Set([0, 408, 502, 503, 504])
6+
export const SKIP_TRANSIENT_RETRY = new HttpContextToken<boolean>(() => false)
67

78
export function retryTransient<T>(
89
maxRetries = 2,

src/app/core/user/user.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'
1+
import {
2+
HttpClient,
3+
HttpContext,
4+
HttpHeaders,
5+
HttpParams,
6+
} from '@angular/common/http'
27
import { Inject, Injectable } from '@angular/core'
38
import {
49
BehaviorSubject,
@@ -56,7 +61,7 @@ import { TogglzFlag } from 'src/app/types/config.endpoint'
5661
import { LOCAL_SESSION_UID } from 'src/app/constants'
5762
import { Params } from '@angular/router'
5863
import { CookieService } from 'ngx-cookie-service'
59-
import { retryTransient } from '../http/retry-transient'
64+
import { retryTransient, SKIP_TRANSIENT_RETRY } from '../http/retry-transient'
6065

6166
@Injectable({
6267
providedIn: 'root',
@@ -568,6 +573,7 @@ export class UserService {
568573
.post(`${runtimeEnvironment.API_WEB}switch-user`, '', {
569574
headers: this.headers,
570575
params: params,
576+
context: new HttpContext().set(SKIP_TRANSIENT_RETRY, true),
571577
})
572578
.pipe(
573579
catchError((error) => {

0 commit comments

Comments
 (0)