Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix error handling in shopping-cart #233

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/contexts/cart-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ export const CartProvider: React.FC<CartProviderProps> = ({ children }) => {
})
.catch((error) => {
setError((prev) => {
return { ...prev, loadCartData: error.errors[0].detail };
return {
...prev,
loadCartData: error.errors?.[0]?.detail || 'Ошибка загрузки корзины покупок',
};
});
})
.finally(() => {
Expand All @@ -140,7 +143,10 @@ export const CartProvider: React.FC<CartProviderProps> = ({ children }) => {
})
.catch((error) => {
setError((prev) => {
return { ...prev, updateCart: error.errors[0].detail };
return {
...prev,
updateCart: error.errors?.[0]?.detail || 'Ошибка обновления корзины покупок',
};
});
})
.finally(() => {
Expand All @@ -154,7 +160,11 @@ export const CartProvider: React.FC<CartProviderProps> = ({ children }) => {
.catch((error) => {
if (error?.errors) {
setError((prev) => {
return { ...prev, deleteCart: error.errors[0]?.detail };
return {
...prev,
deleteCart:
error.errors[0]?.detail || 'Ошибка удаления товара из корзины покупок',
};
});
}
})
Expand All @@ -172,9 +182,12 @@ export const CartProvider: React.FC<CartProviderProps> = ({ children }) => {
return { ...prev, clearCart: message };
});
})
.catch(({ errors }) => {
.catch((error) => {
setError((prev) => {
return { ...prev, clearCart: errors };
return {
...prev,
clearCart: error.errors || 'Ошибка очистки корзины покупок',
};
});
});
};
Expand Down
Loading