Skip to content

unhandled promise rejection when using .catch() #14

@bradwbradw

Description

@bradwbradw
  var request = Request()
    .select("pagepath", "pageviews", "users")
    .from(12345)
    .during("2017-10-31", "2018-10-31")
    .results(3)
    .orderDesc("users");


  let promise = analytics.run(request);

  promise.catch(err => {
    console.log("caught the error: ", err)
  });

Since i supplied a view id i don't have access to (12345), i would expect that the catch block occurs and the console says "caught the error", but instead, i get:


(node:99630) UnhandledPromiseRejectionWarning: Error: User does not have sufficient permissions for this profile.
    at createError (/test/node_modules/node-simple-ga/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/test/node_modules/node-simple-ga/node_modules/axios/lib/core/settle.js:18:12)
    at Unzip.handleStreamEnd (/test/node_modules/node-simple-ga/node_modules/axios/lib/adapters/http.js:201:11)
    at emitNone (events.js:111:20)
    at Unzip.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
(node:99630) 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(). (rejection id: 2)

I'm more comfortable with promise methods like .then and .catch rather than async / await. If analytics.run() actually returns a promise (which it does, according when.isPromiseLike()), then it's natural to expect .catch to work for error handling, isn't it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions