Skip to content

Commit 3c5ec64

Browse files
authored
New timeout system for packager (codesandbox#17)
* Check for status code 408 when retrying * Change status code to 504
1 parent 2c639ee commit 3c5ec64

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/app/store/api/actions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export function createAPIActions(prefix: string, suffix: string): APIActions {
2323
};
2424
}
2525

26-
const getMessage = (error: Error) => {
26+
const getMessage = (error: Error & { response: ?Object }) => {
2727
const response = error.response;
2828

29-
if (response.status >= 500) {
29+
if (!response || response.status >= 500) {
3030
sendError(error);
3131
}
3232

@@ -40,6 +40,7 @@ const getMessage = (error: Error) => {
4040
return errors;
4141
}
4242
}
43+
4344
return error.message;
4445
};
4546

src/app/store/entities/sandboxes/bundler/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const debug = _debug('cs:app:packager');
1111

1212
export const PACKAGER_URL = 'https://cdn.jsdelivr.net/webpack/v3';
1313

14+
const RETRY_COUNT = 10;
15+
1416
/**
1517
* Request the packager, if retries > 4 it will throw if something goes wrong
1618
* otherwise it will retry again with an incremented retry
@@ -28,7 +30,10 @@ async function requestPackager(query: string) {
2830

2931
return { ...result, url };
3032
} catch (e) {
31-
if (retries < 5) {
33+
const statusCode = e.response && e.response.status;
34+
35+
// 504 status code means the bundler is still bundling
36+
if (retries < RETRY_COUNT && statusCode === 504) {
3237
retries += 1;
3338
} else {
3439
throw e;

0 commit comments

Comments
 (0)