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

View File

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