Skip to content

Commit ede22a0

Browse files
committed
fix: catch array errors from API and display error message more detailed
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
1 parent 3aa6c73 commit ede22a0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/actions/base-actions.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import {
1414
getRequest,
1515
createAction,
16+
stopLoading,
1617
authErrorHandler
1718
} from "openstack-uicore-foundation/lib/utils/actions";
1819
import { CODE_200 } from "../utils/constants";
@@ -43,8 +44,20 @@ export const setSnackbarMessage = (message) => (dispatch) => {
4344
};
4445

4546
export const snackbarErrorHandler = (err, res) => (dispatch, state) => {
47+
const errors = err.response?.body?.errors;
48+
49+
if (Array.isArray(errors) && errors.length > 0) {
50+
dispatch(stopLoading());
51+
52+
return setSnackbarMessage({
53+
type: "warning",
54+
html: errors.join("<br>"),
55+
code: err.status || 0
56+
})(dispatch, state);
57+
}
58+
4659
authErrorHandler(err, res, setSnackbarMessage)(dispatch, state);
47-
}
60+
};
4861

4962
export const snackbarSuccessHandler = (message) => (dispatch, state) =>
5063
setSnackbarMessage({ ...message, type: "success", code: CODE_200 })(

0 commit comments

Comments
 (0)