未处理的Promise节点

问题描述

我是新手,目前正在使用React处理约会应用程序的教程。我也在使用cosmicjs CMS。它在localhost上启动,但只说在底部进行加载,并且不允许我与页面进行交互。当我运行npm start时,出现以下错误

 GET / 304 3.235 ms - -

    
GET /bundle.js 304 1.092 ms - -

GET /863be562288d82b810f1a477f15c0254.svg 304 0.399 ms - -

GET /bundle.map.js 304 0.426 ms - -

GET /favicon.ico 302 3.647 ms - 23

GET / 200 1.857 ms - 391

(node:3030) UnhandledPromiseRejectionWarning: 

TypeError: Cannot read property 'Metadata' of undefined
    at /Users/ayr/Desktop/appointment-scheduler/app.js:84:34
    at /Users/ayr/Desktop/appointment-scheduler/node_modules/cosmicjs/index.js:92:16
    at processticksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:3030) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3030) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
console.log(process.env);
GET /api/config - - ms - - 

在文本编辑器中,我还注意到env变量显示为灰色

const app = express()

const env = process.env.NODE_ENV || “发展”

错误中引用的行如下所示

    app.get('/api/config',(req,res) => {
    
      Cosmic.getobject(config,{ slug: 'site-config' },(err,response) => {
    
        const data = response.object.Metadata  
        err ? res.status(500).json({ data: 'error' }) : res.json({ data })
      })
    })

//cosmicjs/index

    getobject: function(config,object,callback){
    
        var endpoint = api_url + '/' + api_version + '/' + config.bucket.slug + '/object/' + object.slug + '?read_key=' + config.bucket.read_key;
        if (object._id) {
          endpoint = api_url + '/' + api_version + '/' + config.bucket.slug + '/object-by-id/' + object._id + '?read_key=' + config.bucket.read_key;
        }
        fetch(endpoint)
        .then(function(response){
          if (response.status >= 400) {
            var err = {
              'message': 'There was an error with this request.'
            }
            return callback(err,false);
          }
          return response.json()
        })
        .then(function(response){
          // Constructor
          var cosmic = {};
          var object = response.object;
          var Metafields = object.Metafields;
          if(Metafields){
            object.Metafield = _.keyBy(Metafields,"key");
          }
          cosmic.object = object;
          return callback(false,cosmic);
        });
      },

这是仓库

https://github.com/cosmicjs/appointment-scheduler

非常感谢您的帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)