Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7767943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:47:51+00:00 2026-06-01T15:47:51+00:00

so I am running into what I think is a binding issue, caused by

  • 0

so I am running into what I think is a binding issue, caused by connect-mongo or expressjs Here is the code:

  //Error
  app.use(function(err, req, res, next) {

        if (err instanceof noData) {
            res.send(err, 404);
        } else {
            next(err);
        }
  });

My custom error handler

function noData(err){
  this.code = 0;
  this.msg = err;
  console.log(Error);
  Error.call(this, {code:0, msg:err});
  Error.captureStackTrace(this, arguments.callee);
};
noData.prototype.__proto__ = Error.prototype;    

Throwing error here:

  err = true;
  //if(err) throw new noData('No Password');
  //Get user from database
  db.collection('users').find({}, {limit:1}).toArray(function(err, result) {
    if(err) throw new noData('No Data');             
  });

The first error throws correctly, but the second one but the second one throws a general nodejs error.

throw e; // process.nextTick error, or 'error' event on first tick

What am i doing wrong here? Is connect-mongo causing it to lose binding somehow?
Any thoughts are greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:47:53+00:00Added an answer on June 1, 2026 at 3:47 pm

    The problem doesn’t lie in express or connect-mongo, the callback is in a different scope. To resolve this simply add a (this) to the end of the call.

      //Get user from database
      db.collection('users').find({}, {limit:1}).toArray(function(err, result) {
        if(err) throw new noData('No Data');             
      }(this));
    

    Now node knows about my custom error. (hallelujah)
    This essentially an iife which allows me to pass in a param.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running into an issue that I think is being caused by needing to
I think I am running into a context issue and hoping someone can shed
I'm using facelet templating and I think I'm running into an issue with ui:define
I am running into an issue in Android where I think I need to
I'm running into an issue trying to use @Html.DropDownListFor(). I have a model with
I'm running into an open cursor limit issue with using the following code. The
Here's an issue I keep running into in Clojure: user=> (max [3 4 5
I am running into a peculiar issue with an app which has multiple Activities.
I think I'm running into an inheritance conceptual wall with my Java arrays. I'm
I've tried nearly everything I can think of, but I'm still running into issues

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.