Skip to content

Commit 78c8535

Browse files
authored
Fix: Unhandled error rejection (#2186)
* task: do not throw an error when response is 403 * task: optional chain res.data * task: show error when api call is not successful
1 parent bace910 commit 78c8535

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/shell/components/load-instance/index.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ export default connect((state) => {
3838
memo(function LoadInstance(props) {
3939
const [error, setError] = useState("");
4040
useEffect(() => {
41-
props
42-
.dispatch(fetchInstance())
43-
.then((res) => {
44-
document.title = `Manager - ${res.data.name} - Zesty`;
45-
CONFIG.URL_PREVIEW_FULL = `${CONFIG.URL_PREVIEW_PROTOCOL}${res.data.randomHashID}${CONFIG.URL_PREVIEW}`;
46-
})
47-
.catch((res) => {
48-
setError(res.message);
49-
});
41+
props.dispatch(fetchInstance()).then((res) => {
42+
if (res.status !== 200) {
43+
setError("You do not have permission to access this instance");
44+
} else {
45+
document.title = `Manager - ${res.data?.name} - Zesty`;
46+
CONFIG.URL_PREVIEW_FULL = `${CONFIG.URL_PREVIEW_PROTOCOL}${res.data?.randomHashID}${CONFIG.URL_PREVIEW}`;
47+
}
48+
});
5049

5150
Promise.all([
5251
props.dispatch(fetchUser(props.user.ZUID)),

src/shell/store/instance.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,14 @@ export function fetchInstance() {
3232
});
3333

3434
return request(`${CONFIG.API_ACCOUNTS}/instances/${ZUID}`).then((res) => {
35-
if (res.status === 403) {
36-
throw new Error(
37-
"You do not have permission to access to this instance"
38-
);
35+
if (res.status === 200) {
36+
dispatch({
37+
type: "FETCHING_INSTANCE_SUCCESS",
38+
payload: {
39+
data: res.data,
40+
},
41+
});
3942
}
40-
dispatch({
41-
type: "FETCHING_INSTANCE_SUCCESS",
42-
payload: {
43-
data: res.data,
44-
},
45-
});
4643

4744
return res;
4845
});

0 commit comments

Comments
 (0)