最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Getting unexpected Error 404 while running an express app. The app is working fine but it is just that error is being

programmeradmin1浏览0评论

I have been trying to create an airbnb clone using Node.js and Express.js for backend. I was consecutively working on other projects also and was getting the same error sometimes. The express app works fine, it is just that this error gets printed on the on the console many times in the airbnb project as well as other projects i was working on simultaneously. I tried to debug it by myself by using the stack trace printed with the error but wasn't successful. Following is the error and its stack trace:

ExpressError: Page Not Found!
    at D:\Programming\WEB DEV\00 Airbnb functioning clone\app.js:107:8
    at Layer.handle [as handle_request] (D:\Programming\WEB DEV\00 Airbnb functioning clone\node_modules\express\lib\router\layer.js:95:5)
    at next (D:\Programming\WEB DEV\00 Airbnb functioning clone\node_modules\express\lib\router\route.js:149:13)
    at next (D:\Programming\WEB DEV\00 Airbnb functioning clone\node_modules\express\lib\router\route.js:145:7)
    at next (D:\Programming\WEB DEV\00 Airbnb functioning clone\node_modules\express\lib\router\route.js:145:7)
    at next (D:\Programming\WEB DEV\00 Airbnb functioning clone\node_modules\express\lib\router\route.js:145:7)
    at next (D:\Programming\WEB DEV\00 Airbnb functioning clone\node_modules\express\lib\router\route.js:145:7)
    at next (D:\Programming\WEB DEV\00 Airbnb functioning clone\node_modules\express\lib\router\route.js:145:7)
    at next (D:\Programming\WEB DEV\00 Airbnb functioning clone\node_modules\express\lib\router\route.js:145:7)
    at Route.dispatch (D:\Programming\WEB DEV\00 Airbnb functioning clone\node_modules\express\lib\router\route.js:119:3) {
  statusCode: 404
}

Now the following is the middleware it is referring to on app.js:107:8

app.all('*', (req, res, next) => {
  next(new ExpressError(404, "Page Not Found!"));
})

And This is the ExpressError class (extends Error) which i am using to represent an error in my project:

class ExpressError extends Error {
    constructor(statusCode, message){
        super();
        this.statusCode = statusCode;
        this.message = message;
    }
}

module.exports = ExpressError;

I am also using WrapAsync function to handle errors occuring in async functions:

module.exports = (fn) => {
    return (req, res, next) => {
        fn(req, res, next).catch(next);
    }
}

Now i wanted to know why is the web app working completely fine though an Error is showing up on the console. I also was not able get to know a page that express was failing to find. What could be the possible reasons for this type of error and still the web app is working fine? Should i also look up at the routes for this error?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论