logo
down
shadow

NodeJS Unhandled Promise Rejection


NodeJS Unhandled Promise Rejection

By : user7455066
Date : November 20 2020, 03:01 PM
may help you . First of all, I would say that dynamic require is a way to get yourself in trouble. Let me structure my answer in two parts, to highlight the reasons why it should be avoided and propose few solutions instead.
Underlying problems
code :
// models/transfer-request.js
class TransferRequest {
  create(instance, cb) {
    // Implementation...
  }
}

module.exports = TransferRequest;

// models/index.js
const TransferRequest = require('./transfer-request.js');
// Other models requires...

module.exports = {
  TransferRequest,
  // Other models exports...
};
class ModelFactory {
  constructor(model){
    switch(model) {
      case 'transferrequest':
        // Implementation of TransferRequest object creation...
      break;

      case 'othertransferrequest':
        // Implementation of OtherTransferRequest object creation...
      break;

      default:
        throw new Error('Unknown class');
    }
  }
}


Share : facebook icon twitter icon
NodeJS: Unhandled Promise Rejection at the end of a method

NodeJS: Unhandled Promise Rejection at the end of a method


By : Phillip Goldberg
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I found the solution! Just use "resolve, request" for creating a promise.
Here is now my method:
code :
public create() : Promise<any> {
    return new Promise((resolve, reject) => {
        User.exists(this.username).then((exists) => {
            if (exists) {
                reject( Errors.mongoose.user_already_exists);
            } else {
                UserModel.create(this.toIUser()).then((result) => {
                    resolve(result);
                }).catch(() => {
                    reject(Errors.mongoose.user_create);
                });
            }
        }).catch((error) => {
            reject(error);
        })
    })
}
User.fromIUser(user).create().then((user) => {
    return response.status(200).send({
        message: "Created",
        user
    });
}).catch((error) => {
    return response.status(500).send({
        message: error
    })
})
NodeJS: Unhandled promise rejection

NodeJS: Unhandled promise rejection


By : Enas Aljmzawy
Date : March 29 2020, 07:55 AM
I wish this helpful for you I'm having a little problem and after debugged all the app I noticed that this is the file that's causing the problem, returning me a UnhandledPromiseRejection
code :
const connection = require('../models/'),
  oracledb   = require('oracledb'),
  conexion   = oracledb.getConnection(connection)
 conexion   = oracledb.getConnection(connection).catch( onRejected)
conexion   = oracledb.getConnection(connection);
conexion.catch(()=>undefined); // a do nothing catch handler.
Unhandled promise rejection using sendgrid and nodejs

Unhandled promise rejection using sendgrid and nodejs


By : Lumaria Camargo
Date : March 29 2020, 07:55 AM
wish of those help try this, You are not handling the error condition. Error: Provide at least one of to, cc or bcc may be to email is null/undefined.
code :
sgMail.send(msg).then(() => {
    res.redirect('/users');
}).catch((error) => {
    console.log('error', error);
});
Nodejs. Unhandled Promise Rejection

Nodejs. Unhandled Promise Rejection


By : coco
Date : March 29 2020, 07:55 AM
this one helps. You should use await before call async function and wrapp await call into try catch construction.
code :
app.post('/sc', async (req, res) => {
    const url = req.body.convo
    try {
      var picture = await getPic(url);
      //some logic or render response
    } catch (error){
       //here you should handle error
    }
})
UnhandledPromiseRejectionWarning: Unhandled promise rejection in nodejs server

UnhandledPromiseRejectionWarning: Unhandled promise rejection in nodejs server


By : user2293478
Date : March 29 2020, 07:55 AM
like below fixes the issue To resolve this specific issue, you need to provide a catch() when you execute User.findOne() at the same level as the outermost then():
code :
User.findOne({ email: email })
  .then(user => { /* existing code */})
  .catch(err => console.log(err)); // add catch()
// Match user
User.findOne({ email: email })
  .then(user => { /* existing code */ })
  .catch(err => console.log(err)); // add catch()
app.set('view engine', 'ejs');
// towards top of file
app.use(express.static(path.join(__dirname, 'path/to/built/angular')));

// ...

// after all other routes
app.get('*', (req, res) =>{
  res.sendFile(path.join(__dirname+'/path/to/built/angular/index.html'));
});
Related Posts Related Posts :
  • How to get text from selected value in a dropdownlist which is js based
  • window is not defined angular universal third library
  • Angularjs ng-repeat stylization depending on previous value
  • Trying to implement Fittext.js
  • Calculate number of match in array Lodash
  • Jquery Smooth Scroll Using Offset.top
  • How to extract data to React state from CSV file using Papa Parse?
  • How to add unique links to google maps markers
  • How to use if condition in a tool bar in java script
  • Ajax filter in django not showing in HTML
  • data collection with Javascript
  • Rotate image on lightbox2 load
  • Prevent body from scrolling when a Pop-Up is open
  • How to copy files that do not need to be compiled in Gulp?
  • Array not assigned to variable? How does this work and what exactly is it doing?
  • Sorting associative array of objects in javascript
  • Changing Icon in Sap.m.tree having CustomTreeItem
  • Merge two array of objects based on a key
  • javascript in css not working
  • Passing only clicked element to onClick function - reactjs
  • React boilerplate doesn't load js files in the index.html
  • is Child service inside child component visible in the Parent component?
  • Check if data attribute value equals a string
  • How to get value of child tag of a button tag
  • How to access subjects of selected mails in Apple Mail using JavaScript?
  • How to get all dynamically set inline-style CSS in jQuery?
  • Error: Module "html" does not provide a view engine (Express)
  • Random Image in <Div> from array
  • Slider with touch function
  • ReactJS Component Architecture Problems / Nested Components or Single Component Manager
  • Javascript: Caching within Closure doesn't work
  • HTM5 Canvas Drawing App: How Do I Select The Color?
  • Assigning Events using HTML DOM
  • html5 getUserMedia() portrait mode
  • How to avoid 'headers already sent' within Promise chain?
  • Get a result from a react native app integrated into an existing android app
  • Why does the value of input field return undefined
  • How to get return object in jquery uploadFile method
  • Javascript string with arguments to single quotes
  • Understanding JS functions syntax (applies to other languages as well, I'm sure)
  • AngularJS Single Page App: Reference Error, ____ is not defined
  • whatwg-fetch new typescript 2.5.3
  • React.js - Array.unshift() not updating array on front-end
  • JavaScript localeCompare don't sort well [ "aaa-1.0", "aaa-1.1", "aaa-1.01", "aaa-11&
  • Mongoose handle validation error in a promise call and Express middleware
  • Building tree array of objects from flat array of objects
  • How to add a progress bar to file upload using javascript and ajax call?
  • JavaScript: is it permitted to override a standard built-in object?
  • Change the current page of an AJAX datatables
  • Array element is undefined even after pushing elements into it
  • onmousemove event not working
  • Chrome-Extension/JavaScript How to make all links on page have no effect?
  • Websocket issue Internet Explorer
  • sessionStorage value becomes null in other tab in AngularJS
  • Split URL from position x to the end in Javascript
  • How to set value of input field with NgIf in Angular 4
  • invalidStateError for second time screenshare on Chrome
  • How do you pass a value to the variable in a xhr.setRequestHeader?
  • I cant start nodemon on my windows 10
  • Nested if else jumps out from the main if else in javascript
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org