Skip to content

Commit

Permalink
Dispatch network fail actions for more failed fetches.
Browse files Browse the repository at this point in the history
Closes #775.

Until now, we only dispatched `..._NETWORK_FAIL` actions when a fetch
failed and the browser deemed it a network error of a certain kind,
per the `message` property of the thrown error. However, we shouldn't
assume that all browsers will set the error's `message` property in
the same way, and we should recover robustly when we are unable to
parse JSON from the response body (e.g. due to an error at the level
of a reverse proxy server).

By being too picky about what the thrown error looked like, we were
failing to clean up after certain kinds of non-HTTP/network error,
which was usually asymptomatic, but in the case of ballot manifest and
CVR export uploads, could lead to a "stuck" spinner state. These
changes fix that.
  • Loading branch information
ranweiler committed Oct 9, 2017
1 parent aaa0a93 commit 1c09e18
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 30 deletions.
12 changes: 2 additions & 10 deletions client/src/action/county/uploadBallotManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ async function importBallotManifest(body: any) {

action('IMPORT_BALLOT_MANIFEST_OK', data);
} catch (e) {
if (e.message === 'Failed to fetch') {
action('IMPORT_BALLOT_MANIFEST_NETWORK_FAIL');
}

action('INTERNAL_ERROR');
action('IMPORT_BALLOT_MANIFEST_NETWORK_FAIL');

throw e;
}
Expand Down Expand Up @@ -75,11 +71,7 @@ async function uploadBallotManifest(countyId: number, file: Blob, hash: string)

importBallotManifest(received);
} catch (e) {
if (e.message === 'Failed to fetch') {
action('UPLOAD_BALLOT_MANIFEST_NETWORK_FAIL');
}

action('INTERNAL_ERROR');
action('UPLOAD_BALLOT_MANIFEST_NETWORK_FAIL');

throw e;
}
Expand Down
12 changes: 2 additions & 10 deletions client/src/action/county/uploadCvrExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ async function importCvrExport(body: any) {

action('IMPORT_CVR_EXPORT_OK', data);
} catch (e) {
if (e.message === 'Failed to fetch') {
action('IMPORT_CVR_EXPORT_NETWORK_FAIL');
}

action('INTERNAL_ERROR');
action('IMPORT_CVR_EXPORT_NETWORK_FAIL');

throw e;
}
Expand Down Expand Up @@ -75,11 +71,7 @@ async function uploadCvrExport(countyId: number, file: Blob, hash: string) {

importCvrExport(received);
} catch (e) {
if (e.message === 'Failed to fetch') {
action('UPLOAD_CVR_EXPORT_NETWORK_FAIL');
}

action('INTERNAL_ERROR');
action('UPLOAD_CVR_EXPORT_NETWORK_FAIL');

throw e;
}
Expand Down
6 changes: 1 addition & 5 deletions client/src/action/createFetchAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ function createFetchAction(config: CreateFetchConfig) {

action(okType, data);
} catch (e) {
if (e.message === 'Failed to fetch') {
action(networkFailType);
}

action('INTERNAL_ERROR');
action(networkFailType);

throw e;
}
Expand Down
6 changes: 1 addition & 5 deletions client/src/action/createSubmitAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ function createSubmitAction(config: CreateSubmitConfig) {

action(okType, data);
} catch (e) {
if (e.message === 'Failed to fetch') {
action(networkFailType);
}

action('INTERNAL_ERROR');
action(networkFailType);

throw e;
}
Expand Down

0 comments on commit 1c09e18

Please sign in to comment.