6/21/2023 0 Comments React expressImproper Express error handling example res.status(200).json('404 - no user exists in db to update') ![]() I must confess, for quite a while, in the course of building this app, I passed back HTTP 200 status (the OK status) codes from the Express server even when an error like a missing JWT token or user ID was not found in the database. Since the server side is where the majority of the errors occur from, starting with the Node.js / Express server code is where I’ll begin as well. Today I’m talking about how to properly handle errors on both sides of a JavaScript application: from throwing errors on the server side in Express, to catching and handling them on the client side with React and Axios. If you want to see the rest of my posts pertaining to this repo and the code itself, I’ll link to them all at the bottom of this article. Honestly, working through building this application, just for the sake of learning more Node, more React, more core JavaScript, taught me so much. Past topics included using Sequelize as the ORM for a MySQL database, using PassportJS and JWT for authentication and protected routes, using Nodemailer to provide password reset capability via email, etc. ![]() As I slowly built it out and added more bells and whistles to it, I learned a slew of new things worth sharing to help other devs avoid obstacles that I ran into along the way. I’ve used a full stack MERN (MySQL, Express, React and Node.js) project I made from scratch for a whole handful of blog posts now. Photo by Jamie Street on Unsplash Introduction
0 Comments
Leave a Reply. |