This isn’t error handling: .catch((error) => { console.log(error); });...
This isn’t error handling:
.catch((error) => {
console.log(error);
});
That’s error swallowing. 😬
The user doesn’t watch the console. So, they don't know an error occurred.
The solution? Show a message when an error occurs.
.catch((error) => {
setError(error);
});
In react, I like to use the react-error-boundary so the user can click "try again" to reset the app. https://www.npmjs.com/package/react-error-boundary
Also: I recommend using ESLint to forbid using console.log. Doing so discourages swallowing errors via the console.
https://eslint.org/docs/latest/rules/no-console
Clarification: In the example above I stored the error in state to keep the example simple. And capturing the actual error is useful for logging.
But, avoid showing the user the actual error. Show a friendly, general error message instead.