Skip to content

Commit

Permalink
error handling in bucket creation ui
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashsvmx committed Oct 22, 2024
1 parent 06af416 commit 8741e78
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const AddBucket = () => {
(state: AppState) => state.addBucket.retentionValidity,
);
const addLoading = useSelector((state: AppState) => state.addBucket.loading);
const addError = useSelector((state: AppState) => state.addBucket.error);
const invalidFields = useSelector(
(state: AppState) => state.addBucket.invalidFields,
);
Expand Down Expand Up @@ -155,6 +156,12 @@ const AddBucket = () => {
IAM_SCOPES.S3_PUT_ACTIONS,
]);

useEffect(() => {
if (addError) {
dispatch(setErrorSnackMessage(errorToHandler(addError)));
}
}, [addError, dispatch]);

useEffect(() => {
const bucketNameErrors = [
!(isDirty && (bucketName.length < 3 || bucketName.length > 63)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ export const addBucketAsync = createAsyncThunk(
};
}
}

return api.buckets.makeBucket(request);
try {
return await api.buckets.makeBucket(request);
} catch (err: any) {
return rejectWithValue(err.error);
}
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface AddBucketState {
navigateTo: string;
excludeFolders: boolean;
excludedPrefixes: string;
error: any;
}

const initialState: AddBucketState = {
Expand All @@ -56,6 +57,7 @@ const initialState: AddBucketState = {
navigateTo: "",
excludeFolders: false,
excludedPrefixes: "",
error: null,
};

const addBucketsSlice = createSlice({
Expand Down Expand Up @@ -180,15 +182,20 @@ const addBucketsSlice = createSlice({
builder
.addCase(addBucketAsync.pending, (state) => {
state.loading = true;
state.error = null;
})
.addCase(addBucketAsync.rejected, (state) => {
.addCase(addBucketAsync.rejected, (state, action) => {
state.loading = false;
state.error = action.payload;
})
.addCase(addBucketAsync.fulfilled, (state, action) => {
state.loading = false;
state.navigateTo = action.payload.data.bucketName
? "/buckets"
: `/buckets/${action.payload.data.bucketName}/admin`;
state.error = null;
if (action.payload) {
state.navigateTo = action.payload.data.bucketName
? "/buckets"
: `/buckets/${action.payload.data.bucketName}/admin`;
}
});
},
});
Expand Down

0 comments on commit 8741e78

Please sign in to comment.