Skip to content

Excessive and confusing Node error when an async Lambda fails #442

Description

@peterm06

This is a follow up to my prior PR: #440

When I fail a Lambda by throwing an unhandled Error, node-lambda outputs a Node runtime error and deprecation warning as seen below:

(node:12256) UnhandledPromiseRejectionWarning: Error: Error getting token from Salesforce
at exports.handler (C:\...index.js:79:11)
at <anonymous>
at process._tickDomainCallback [as _tickCallback] (internal/process/next_tick.js:228:7)
(node:12256) 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: 1)
(node:12256) [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.

When I run the same Lambda in AWS it would fail and return an error object. That Node error is just sloppy code from my prior PR. I was not handling the rejected promise in the .then() method. The fix would look like going from:

Promise.resolve(result).then(resolved=>{console.log("Result:");console.log(JSON.stringify(resolved));});

to

Promise.resolve(result).then(resolved=>{console.log("Result:");console.log(JSON.stringify(resolved));},rejected=>{console.log("Error:");console.log(rejected);});

Want me to open a PR for this fix?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions