Using Custom Javascript Errors

added by JavaScript Kicks
12/20/2019 2:17:18 PM


This code should look familiar to you: function validateUser({ userId, password }) { try {'https://my-login-endpoint', { userId, password }); } catch (e) { if (e.response.status === 400) { displayError(; } else { displayError("Something went wrong."); // Generic error } }} The displayError is a custom function that I assume you have written that either ends up displaying the error in a modal directly or if you are using React it dispatches another action that sets the error property in one of your reducers to or a generic error accordingly.