Node js - Promise Rejection Warning when process a lot of data

前端 未结 1 944
自闭症患者
自闭症患者 2020-12-22 12:27

I\'m creating a feature that when you pass a bar code, the product of bar code is added to a table.

After that we have a button to save the data in table. For each r

相关标签:
1条回答
  • 2020-12-22 13:30

    Your code example is 150 lines of code so I won't debug all of that (you should always provide a minimal code example needed to reproduce your problem and include in the question if you want people to help you spot and fix the actual errors) but the UnhandledPromiseRejectionWarning means that somewhere you didn't include a catch handler for a promise.

    For example, if anywhere you have:

    promise.then(func);
    

    instead of:

    promise.then(func1, func2);
    

    or:

    promise.then(func1).catch(func2);
    

    Then your code is not halndling the promise rejections properly and as such is broken. In the future this program may not even start in next versions of Node - I explained it in more details in this answer:

    • Should I refrain from handling Promise rejection asynchronously?

    Also, having looked at your code I strongly suggest reading about SQL injection attacks. I mean it. Google the subject and fix your code even before you fix the problem with unhandled promise rejections. Seriously. I'm not referring to this comic strip any more these years but every developer should know it and understand:

    Please read:

    • https://en.wikipedia.org/wiki/SQL_injection
    • http://www.beyondsecurity.com/about-sql-injection.html
    • http://projects.webappsec.org/w/page/13246963/SQL%20Injection
    • http://bobby-tables.com/
    0 讨论(0)
提交回复
热议问题