guard clause for api error (#11436)

This commit is contained in:
Josh Hawkins 2024-05-19 18:08:05 -05:00 committed by GitHub
parent c1560308bf
commit bca01cb43c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -25,7 +25,10 @@ export function ApiProvider({ children, options }: ApiProviderType) {
return axios.get(path, { params }).then((res) => res.data); return axios.get(path, { params }).then((res) => res.data);
}, },
onError: (error, _key) => { onError: (error, _key) => {
if ([401, 302, 307].includes(error.response.status)) { if (
error.response &&
[401, 302, 307].includes(error.response.status)
) {
window.location.href = window.location.href =
error.response.headers.get("location") ?? "login"; error.response.headers.get("location") ?? "login";
} }