title: Unhandled rejection TypeError: Cannot read property 'name' of null
body: <p>Following is my code:</p>
  
  <pre><code>router.post('/getTrainingProgramByTPType', function (req, res) {
      var query = { ... }; // simplified for clarity in stackoverflow
  
      models.TrainingProgram.findAll(query).then(function (trainingPrograms) {
          var resData = [];
          console.log(typeof req.body.userType, req.body.userType);
  
          trainingPrograms.forEach(trainingProgram =&gt; {
              if (trainingProgram.CourseType.name === req.body.userType || trainingProgram.CourseType.name === "EVERYONE" || (!req.body.isExperienced &amp;&amp; trainingProgram.CourseType.name === "OPTIONAL")) {
                  resData.push(trainingProgram);
              }
              else {
                  var resDataCourse = [];
                  var a;
                  trainingProgram.Courses.forEach(course =&gt; {
                      course.Classes.forEach(classes =&gt; {
                          classes.ClassRecords.forEach(classRecord =&gt; {
                              if (classRecord.User.email === req.body.email) {
                                  a = 1;
                                  resDataCourse.push(course);
                              }
                          });
                      });
                  });
  
                  if (a === 1) {
                      resData.push({
                          id: trainingProgram.id,
                          name: trainingProgram.name,
                          description: trainingProgram.description,
                          imgLink: trainingProgram.imgLink,
                          courseTypeId: trainingProgram.courseTypeId,
                          CourseType: trainingProgram.CourseType,
                          Courses: resDataCourse
                      });
                  }
              }
          });
  
          var datasend = {
              success: true,
              msg: 'send list success',
              trainingProgram: resData,
          };
          res.send(datasend);
      });
  });
  </code></pre>
  
  <p>And I'm getting this error:</p>
  
  <blockquote>
  <pre><code>at Promise._settlePromiseFromHandler (C:\Users\huy.q.lam\Desktop\master\DEK-Talentnet\DCC\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:522:17)
  at Promise._settlePromise (C:\Users\huy.q.lam\Desktop\master\DEK-Talentnet\DCC\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:567:18)
  at Promise._settlePromise0 (C:\Users\huy.q.lam\Desktop\master\DEK-Talentnet\DCC\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:612:10)
  at Promise._settlePromises (C:\Users\huy.q.lam\Desktop\master\DEK-Talentnet\DCC\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:691:18)
  at Promise._fulfill (C:\Users\huy.q.lam\Desktop\master\DEK-Talentnet\DCC\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:636:18)
  at MappingPromiseArray.PromiseArray._resolve (C:\Users\huy.q.lam\Desktop\master\DEK-Talentnet\DCC\node_modules\sequelize\node_modules\bluebird\js\release\promise_array.js:125:1 9)
  at MappingPromiseArray._promiseFulfilled (C:\Users\huy.q.lam\Desktop\master\DEK-Talentnet\DCC\node_modules\sequelize\node_modules\bluebird\js\release\map.js:101:18)
  at Promise._settlePromise (C:\Users\huy.q.lam\Desktop\master\DEK-Talentnet\DCC\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:572:26)
  at Promise._settlePromise0 (C:\Users\huy.q.lam\Desktop\master\DEK-Talentnet\DCC\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:612:10)
  at Promise._settlePromises (C:\Users\huy.q.lam\Desktop\master\DEK-Talentnet\DCC\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:691:18)
  at Promise._fulfill (C:\Users\huy.q.lam\Desktop\master\DEK-Talentnet\DCC\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:636:18)
  at Promise._resolveCallback (C:\Users\huy.q.lam\Desktop\master\DEK-Talentnet\DCC\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:431:57)
  </code></pre>
  </blockquote>
  
  <p>What might be causing the TypeError?</p>