Skip to content

Commit 376779c

Browse files
authored
Merge pull request #1390 from guardian/pf/handle-createUpload-errors
Catch errors from the createUpload call
2 parents b43510d + fc9629d commit 376779c

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

public/video-ui/src/slices/s3Upload.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit';
2-
import { showError } from './error';
3-
import { errorDetails } from '../util/errorDetails';
42
import {
53
createUpload,
64
deleteSubtitleFile,
75
uploadParts,
86
uploadSubtitleFile
97
} from '../services/UploadsApi';
8+
import { errorDetails } from '../util/errorDetails';
9+
import { showError } from './error';
1010

1111
export type YouTubeAsset = { id: string; sources?: undefined };
1212
export type SelfHostedAsset = { id?: undefined; sources: unknown[] };
@@ -39,19 +39,21 @@ export const startVideoUpload = createAsyncThunk<
3939
unknown,
4040
{ id: string; file: File; selfHost?: boolean }
4141
>('s3Upload/startVideoUpload', ({ id, file, selfHost }, { dispatch }) =>
42-
createUpload(id, file, selfHost).then((upload: Upload) => {
43-
dispatch(s3UploadStarted(upload));
42+
createUpload(id, file, selfHost)
43+
.then((upload: Upload) => {
44+
dispatch(s3UploadStarted(upload));
4445

45-
const progress = (completed: number) =>
46-
dispatch(s3UploadProgress(completed));
46+
const progress = (completed: number) =>
47+
dispatch(s3UploadProgress(completed));
4748

48-
return uploadParts(upload, upload.parts, file, progress)
49-
.then(() => dispatch(setS3UploadStatusToComplete()))
50-
.catch(err => {
51-
dispatch(showError(errorDetails(err), err));
52-
dispatch(setS3UploadStatusToError());
53-
});
54-
})
49+
return uploadParts(upload, upload.parts, file, progress).then(() =>
50+
dispatch(setS3UploadStatusToComplete())
51+
);
52+
})
53+
.catch(err => {
54+
dispatch(showError(errorDetails(err), err));
55+
dispatch(setS3UploadStatusToError());
56+
})
5557
);
5658

5759
export const startSubtitleFileUpload = createAsyncThunk<

0 commit comments

Comments
 (0)