Added http errors handing to all fettch requests

This commit is contained in:
2023-07-13 17:50:20 +03:00
parent d041df0bbd
commit 6a0c4c9dac
6 changed files with 33 additions and 13 deletions

View File

@ -1,3 +1,17 @@
const isAborted = (err: Error) => err.name === 'AbortError'
export { isAborted }
const handleHTTPErrors = (res: Response) => {
if (!res.ok) {
switch (res.status) {
case 401:
throw new Error("Ошибка авторизации")
case 404:
throw new Error("Объект не найден")
default: {
throw new Error("Ошибка ответа от сервера")
}
}
}
}
export { isAborted, handleHTTPErrors }