We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have a barrier like this:
export const authBarrier = createBarrier({ activateOn: { failure: isHttpErrorCode(401) }, perform: [getTokenMutation], })
But I had a bug in a query header where I mistyped AuthoriZation with AuthoriSation:
createJsonQuery({ request: { method: 'GET', url: API_URL + '/presets', headers: { source: $authToken, fn: (_, token) => ({ Authorisation: `Bearer ${token}` }) } }, ... })
So the backend returned 401 even after updating the token, which led to an infinite loop, freeze, and a lot of requests.
I've written an ugly workaround for this problem:
export const createCircuitBreaker = (maxRetries: number = 3) => { let retries = 0; // Circuit breaker. Prevent infinite loop const circuitBreaker = () => { const pass = ++retries < maxRetries; if (!pass) { setTimeout(() => { retries = 0; }, 0); } return pass; }; return circuitBreaker; }; export const withCircuitBreaker = (condition: (...args: any[]) => boolean) => { const circuitBreaker = createCircuitBreaker(); return (e: { params: unknown, error: unknown }) => condition(e) && circuitBreaker(); }; export const authBarrier = createBarrier({ activateOn: { failure: withCircuitBreaker(isHttpErrorCode(401)) }, perform: [getTokenMutation], });
But I think something like this should be a part of the barrier config.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I have a barrier like this:
But I had a bug in a query header where I mistyped AuthoriZation with AuthoriSation:
So the backend returned 401 even after updating the token, which led to an infinite loop, freeze, and a lot of requests.
I've written an ugly workaround for this problem:
But I think something like this should be a part of the barrier config.
The text was updated successfully, but these errors were encountered: