Skip to content

Commit 5917b83

Browse files
authored
fix(refresh-token): add retry mechanism with back off to emit new AT (#199)
* fix(refresh-token): add retry mechanism with back off to emit new AT * chore(ci): add jest run * chore(ci): add build test * fix(refresh-token): fix retry exhaustion bug, dropzone accept callback, and response.ok handling * Fix retryWithBackoff exhaustion guard (attempt === maxRetries was dead code after loop bound change to < maxRetries; errors were silently swallowed, function returned undefined instead of throwing). * Fix Dropzone accept callback to call done() on error path, preventing files from getting stuck in an indeterminate state. * Use response.ok instead of checking individual status codes, closing a gap where 4xx codes other than 400 fell through unhandled. * Add ok property to existing test mocks to match the new response.ok check. * Export retryWithBackoff and add 5 unit tests covering retry count, auth error short-circuit, transient recovery, and exponential backoff. * Add defensive check for missing access_token in refresh response. * fix(refresh-token): The loop bound is now attempt < maxRetries * consistent with the exhaustion guard attempt === maxRetries - 1. With MAX_RETRIES = 5, the function makes exactly 5 attempts (0 through 4), no dead code. * fix(refresh-token): improved HTTP error handling
1 parent 6a2f18b commit 5917b83

7 files changed

Lines changed: 487 additions & 39 deletions

File tree

.github/workflows/build_test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: build_test
2+
3+
on: [push, pull_request]
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v3
9+
with:
10+
fetch-depth: 0
11+
- uses: actions/setup-node@v3
12+
with:
13+
node-version: 18
14+
- run: yarn install
15+
- run: yarn build

.github/workflows/jest.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: jest
2+
3+
on: [push, pull_request]
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v3
9+
with:
10+
fetch-depth: 0
11+
- uses: actions/setup-node@v3
12+
with:
13+
node-version: 18
14+
- run: yarn install
15+
- run: yarn test

src/components/extra-questions/__test__/extra-questions.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import {toSlug} from '../../../utils/methods';
1111

1212
Enzyme.configure({adapter: new Adapter()});
1313

14+
// jsdom does not implement scrollIntoView
15+
Element.prototype.scrollIntoView = jest.fn();
16+
1417
const questions = [
1518
{
1619
"id": 93,

src/components/inputs/upload-input-v2/dropzone.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'dropzone/dist/dropzone.css';
44
import {Icon} from './icon'
55
import PropTypes from 'prop-types';
66
import {getAccessToken, initLogOut} from '../../security/methods';
7+
import {AUTH_ERROR_REFRESH_TOKEN_NETWORK_ERROR} from '../../security/constants';
78
import {getMD5} from "../../../utils/crypto";
89

910
let Dropzone = null;
@@ -61,7 +62,12 @@ export class DropzoneJS extends React.Component {
6162
} catch (e) {
6263
console.log(e);
6364
this.onError(e);
64-
initLogOut();
65+
// only logout on genuine auth errors, not transient network failures
66+
if (!e.message || !e.message.startsWith(AUTH_ERROR_REFRESH_TOKEN_NETWORK_ERROR)) {
67+
initLogOut();
68+
}
69+
done(e.message || 'Auth error');
70+
return;
6571
}
6672
if (options.maxFiles && options.maxFiles < (this.state.files.length + this.props.uploadCount)) {
6773
done('Max files reached.');

0 commit comments

Comments
 (0)