We have been getting this 404 error message on our server for months now and have been ignoring the message but it hasn't gone away, and I have no idea where it comes from:
"Error: 404: Not Found",
" at /opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/setup/setupExpress.js:47:15",
" at Layer.handle [as handle_request] (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/layer.js:95:5)",
" at trim_prefix (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:312:13)",
" at /opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:280:7",
" at Function.process_params (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:330:12)",
" at next (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:271:10)",
" at jsonParser (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/body-parser/lib/types/json.js:100:40)",
" at Layer.handle [as handle_request] (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/layer.js:95:5)",
" at trim_prefix (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:312:13)",
" at /opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:280:7",
"Error: 404: Not Found",
" at /opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/setup/setupExpress.js:47:15",
" at Layer.handle [as handle_request] (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/layer.js:95:5)",
" at trim_prefix (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:312:13)",
" at /opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:280:7",
" at Function.process_params (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:330:12)",
" at next (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:271:10)",
" at jsonParser (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/body-parser/lib/types/json.js:100:40)",
" at Layer.handle [as handle_request] (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/layer.js:95:5)",
" at trim_prefix (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:312:13)",
" at /opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:280:7",
"Error: 404: Not Found",
" at /opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/setup/setupExpress.js:47:15",
" at Layer.handle [as handle_request] (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/layer.js:95:5)",
" at trim_prefix (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:312:13)",
" at /opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:280:7",
" at Function.process_params (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:330:12)",
" at next (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:271:10)",
" at jsonParser (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/body-parser/lib/types/json.js:100:40)",
" at Layer.handle [as handle_request] (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/layer.js:95:5)",
" at trim_prefix (/opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:312:13)",
" at /opt/csv/var/lib/smartconnect/0.0.2-csv.139/nodejs/node_modules/express/lib/router/index.js:280:7",
any idea?
each block is identical, I just kept the repeats so you know that you got the entire error stack
(you can ignore the extra quotes on each line, they have to do with JSON formatting in browser output)
line 47 of our Express app, is of course
// catch 404 and forward to error handler
app.use(function (req, res, next) {
var err = new Error('404: Not Found'); //this line :)
err.status = 404;
next(err);
});
so that doesn't help
Basically what is happening is that in your code above, you are creating a new Error object on line 47, and then you are calling next(err). If you do not then have any kind of app.use(function (err, req, res, next) { declaration after that middleware, the error will be automatically handled by Express, which includes printing the error's stack trace to STDERR.
yeah, I guess my question is that I have no idea where the 404 originates from. I am sure it's my error not Express' but it is a mystery. I just changed the above to this:
// catch 404 and forward to error handler
app.use(function (req, res, next) {
var err = new Error('404: Not Found ' + req.originalUrl); //here
err.status = 404;
next(err);
});
we'll see if I can track it down. The other possiblity is that I am doing this somewhere in the code
next(null);
res.send({});
so what's happening is that the response is being sent successfully, but the 404 error handler is also being invoked, this is probably the case, you can just close this ticket, it's probably my mistake
Ah, I see what you mean; I misunderstood your original request :)
So, looking at your stack trace there, you can rule out the possibility of those being generated from a next(null); res.send({})';, as it shows that a request came in, went through your bodyParser.json() and then ended, due to no routes being matched.
Your idea of adding req.originalUrl will be your best bet, as based on the stack trace, it's just a request coming into your server that you have no route for. The most common ones would be /favicon.ico or /robots.txt if you don't have those on your server.
i see, yeah, that could be it, will let you know, the 404s appeart out of nowhere
I also got the same error and found this thread while searching an answer.
Here I'm sharing the way that you should tackle this error.
1) First comment out the lines which handle your 404 error.
// catch 404 and forward to error handler
// app.use(function (req, res, next) {
// var err = new Error('404: Not Found ' + req.originalUrl); //here
// err.status = 404;
// next(err);
// });
2) Now reload your page and you will see something like
Cannot GET /(some route)
3) Understanding: The 404 or Not Found error message is the standard HTTP response code, to indicate that the client was able to communicate with a given server, but the server could not find what was requested. And it now says the missing resource is on the route "/(some route)".
4) Handling the error
If it's a web page, the problem is "/(some route)" cannot be found in the JS files in ~/routes/ directory. You may have forgotten to handle that route or can be a typo or something. Handle it appropriately.
If it's a resource, make sure the resource exists in the mentioned route of your project.
For me they were requests to the sourceMapping (.js.map) files for 3rd party js files - I removed the //#sourceMappingURL line in the files.
Most helpful comment
For me they were requests to the sourceMapping (.js.map) files for 3rd party js files - I removed the //#sourceMappingURL line in the files.