Using Custom Javascript Errors

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

304 Views

This code should look familiar to you: function validateUser({ userId, password }) { try { axios.post('https://my-login-endpoint', { userId, password }); } catch (e) { if (e.response.status === 400) { displayError(e.response.data.detail); } 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 e.response.data.detail or a generic error accordingly.


0 comments