MERN stack err.kind expression: Where does it come from?

I’m trying to go into MERN stack development lately, and I saw in a tutorial an Error Handling expression being used in order identify what type of error is being thrown. As I’ve seen so far, below expressions can be used, and they seem to be using standard js libraries. === "example"
err.message.indexOf('Cast to ObjectId failed') !== -1
err.message instanceof mongoose.Error.CastError

But then I saw this way of handling an error, which is using the "error.kind" property. I went around to figure out where it comes from and what kind of values I should be expecting from it without success.

Hoping you can shed some light on below questions:

  • From which library is "error.kind" coming from ? is it coming from the standard JS code library ?
  • Is it coming from Mongoose ? Node ? Express ?

I’m obviously still confused at this stage, so happy to go over any reading material you’d recommend.

router.get('/user/:user_id',async (req,res)=>{

    try {
        const profile = await Profile.findOne({user:req.params.user_id}).populate('User',['name','avatar']);

        return res.status(400).json({msg:'There is no profile for the user'});


    } catch (err) {

        if(err.kind == 'ObjectId'){
            return res.status(400).json({msg:'There is no profile for the user'});

        res.status(500).json({msg:'Server Error'});


37 thoughts on “MERN stack err.kind expression: Where does it come from?”

  1. I’m not certain where you’re getting your info, however good topic.
    I needs to spend some time studying much more or working out
    more. Thank you for great info I was looking for this information for
    my mission.

  2. Admiring the hard work you put into your website and in depth information you present.
    It’s good to come across a blog every once in a while that isn’t the same out of date
    rehashed information. Great read! I’ve bookmarked your site and I’m adding
    your RSS feeds to my Google account.

  3. It’s perfect time to make a few plans for the future and it’s time to be happy.
    I have learn this put up and if I may just I wish to recommend you some attention-grabbing issues or advice.
    Maybe you could write next articles relating to this article.

    I want to learn more things about it!

  4. I’m really enjoying the theme/design of your web site.

    Do you ever run into any browser compatibility problems? A couple
    of my blog readers have complained about my website not working correctly in Explorer
    but looks great in Chrome. Do you have any advice to help fix this problem?

  5. When I originally commented I clicked the
    “Notify me when new comments are added” checkbox and now each
    time a comment is added I get three emails with the same comment.

    Is there any way you can remove me from that service?
    Thank you!

  6. I will right away grab your rss as I can not find your email subscription hyperlink or newsletter service.
    Do you have any? Please allow me realize so that I may
    just subscribe. Thanks.

  7. Pretty section of content. I just stumbled
    upon your blog and in accession capital to assert
    that I acquire actually enjoyed account your
    blog posts. Anyway I’ll be subscribing to your feeds and even I achievement you access consistently quickly.

  8. I was recommended this web site by my cousin. I’m not sure whether this post is written by him as nobody
    else know such detailed about my difficulty.
    You are incredible! Thanks!

  9. First of all I would like to say wonderful blog! I had a quick
    question which I’d like to ask if you don’t mind.
    I was interested to find out how you center yourself
    and clear your thoughts before writing. I’ve had a hard time clearing
    my mind in getting my ideas out there. I do
    enjoy writing but it just seems like the first 10
    to 15 minutes are usually lost simply just trying to figure out how
    to begin. Any suggestions or hints? Thanks!

  10. I every time used to read piece of writing in news papers but now as I am a user of net therefore from now I am using net for posts, thanks to web.

  11. Interesting blog! Is your theme custom made or did you download
    it from somewhere? A design like yours with a few simple adjustements would really make my blog stand out.

    Please let me know where you got your theme. Cheers

  12. This is very interesting, You’re a very skilled blogger.
    I’ve joined your rss feed and look forward to seeking more of your great post.
    Also, I’ve shared your site in my social networks!

  13. Hello! I know this is kinda off topic but I’d figured I’d
    ask. Would you be interested in exchanging links or maybe guest authoring
    a blog article or vice-versa? My blog discusses a lot of the same subjects as yours and
    I feel we could greatly benefit from each other.
    If you’re interested feel free to send me an email.
    I look forward to hearing from you! Wonderful blog by the way!

  14. Greetings! Very helpful advice within this post! It is the little changes that will make the
    most significant changes. Many thanks for sharing!

  15. I’m not that much of a internet reader to be honest but your blogs
    really nice, keep it up! I’ll go ahead and bookmark your website to come back in the future.
    Many thanks

  16. Hey! This is kind of off topic but I need some help from an established
    blog. Is it very difficult to set up your own blog? I’m not
    very techincal but I can figure things out pretty quick.
    I’m thinking about creating my own but I’m
    not sure where to begin. Do you have any points or suggestions?

  17. Excellent items from you, man. I’ve bear in mind your stuff previous to
    and you are just extremely fantastic. I actually like what you’ve bought right here, certainly like what
    you are stating and the way in which by which you say it.
    You are making it enjoyable and you continue to take care of to keep it smart.
    I cant wait to read much more from you. That is really a terrific website.

  18. you’re in reality a good webmaster. The site loading pace is incredible.
    It sort of feels that you’re doing any unique trick.

    Moreover, The contents are masterpiece. you’ve performed a great job on this topic!

  19. My brother recommended I might like this website.

    He was totally right. This post actually made my day.
    You cann’t imagine simply how much time I had spent for this info!