NodeJS returning JSON, but not to client properly

NodeJS returning JSON, but not to client properly

So, I have a route that is authing a user based on username and password input. The first validation check, I just can't seem to get to work:

So, I have a route that is authing a user based on username and password input. The first validation check, I just can't seem to get to work:

exports.user_login = (req, res, next) => {
    passport.authenticate('local', { session: false }, (err, user, info) => {
        if (err || !user) {
            res.status(500).json({
                errorMsg: "User could not be authenticated."
            });
        }

If I ping this via postman, I get the appropriate JSON response back that the User could not be authenticated.

However, if I use this route from my client-side code, and try to console.log it, or whatever else (essentially, I want to pull whatever the errorMsg is, log it in state, and reflect that back to the user), then I just get the following response:

axios.post("api/auth/login/", user)
            .then(res => {
                console.log(res);
                this.setState({
                    username: "",
                    password: ""
                })
                localStorage.setItem('bdgt', res.data.token);
            })
            .catch(err => {
                console.log(err);

        })

I've looked at other code I've done before, and usually this works, and I can typically access the message and store it to state by:

this.setState({
     error: err.errorMsg
})

Thoughts? What am I missing?

EDIT ... If I just let it do res.json({ errorMsg: "message....."}) ... this works just fine, but returns a 200 which is obviously not what I want.

node-js reactjs express json

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How to Use Express.js, Node.js and MongoDB.js

In this post, I will show you how to use Express.js, Node.js and MongoDB.js. We will be creating a very simple Node application, that will allow users to input data that they want to store in a MongoDB database. It will also show all items that have been entered into the database.

Ecommerce MERN(MongoDB Express.js React.js Node.js) Redux Tailwind

Ecommerce MERN(MongoDB Express.js React.js Node.js) Redux Tailwind

Node.js Express MongoDB Tutorial

Node.js Express MongoDB Tutorial is CRUD example, I have created to showcase Express web framework, MongoDB NoSQL database, and Node.js server platform.

Node.js Express Tutorial | What Is Node.js Express

Express is a flexible Node.js web application framework which provides a wide set of features to develop both web and mobile applications. We dive into the features of this framework and also create a basic web application using Express.

How to Hire Node.js Developers And How Much Does It Cost?

A Guide to Hire Node.js Developers who can help you create fast and efficient web applications. Also, know how much does it cost to hire Node.js Developers.