Skip to content

Commit

Permalink
error handling in bucket creation ui (#3455)
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashsvmx authored Oct 28, 2024
1 parent 3d74e97 commit 854a0c1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 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 @@ -16,7 +16,7 @@

import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { addBucketAsync } from "./addBucketThunks";
import { ObjectRetentionMode } from "api/consoleApi";
import { ApiError, ObjectRetentionMode } from "api/consoleApi";

interface AddBucketState {
loading: boolean;
Expand All @@ -36,6 +36,7 @@ interface AddBucketState {
navigateTo: string;
excludeFolders: boolean;
excludedPrefixes: string;
error: ApiError | null;
}

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 as ApiError;
})
.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 854a0c1

Please sign in to comment.