Unhandled Promise node

I’m new to currently working through a tutorial for an appointment app using react. I’m also using cosmicjs CMS. It pulls up on localhost but just says loading at the bottom, and won’t allow me to interact the page. When I run npm start, I get the following error

 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 - -  

I’ve also noticed in my text editor that env variable is greyed out

const app = express()

const env = process.env.NODE_ENV || ‘development’

The lines referenced in the error look like this

    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);         });       }, 

Here is the repo

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

Any help is greatly appreciated!

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.