# Console.log and throw error in callbacks

**URL:** <https://community.auth0.com/t/console-log-and-throw-error-in-callbacks/67952>\
**Category:** Get Help\
**Created:** [August 14, 2021, 11:49pm UTC](https://community.auth0.com/t/console-log-and-throw-error-in-callbacks/67952 "2021-08-14T23:49:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kewur](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kewur/32/25980_2.png) [@kewur](https://community.auth0.com/u/kewur)\
**Post date:** [August 14, 2021, 11:49pm UTC](https://community.auth0.com/t/console-log-and-throw-error-in-callbacks/67952/1 "2021-08-14T23:49:25Z")

</div>

Hi,

I’m trying to implement logging and erroring when a remote call fails through callbacks like so.

```auto
    client.send(command).then(data => {
        console.log('[Success]' + data);
    }).catch(error => {
        console.log('[Error]' + JSON.stringify(error, null));
        throw new Error('User ' + JSON.stringify(event.user) + 'error: ' + error);
    });

```

But neither my logs nor my errors are being picked up by the action. Am I doing this incorrectly? This same code works in my local IDE and is able to print out the message. I am using the testing feature the action editor has.

---

<div class="post-metadata">

**Author:** ![thameera](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/thameera/32/13430_2.png) [@thameera](https://community.auth0.com/u/thameera)\
**Post date:** [August 15, 2021, 4:28am UTC](https://community.auth0.com/t/console-log-and-throw-error-in-callbacks/67952/2 "2021-08-15T04:28:14Z")

</div>

Given actions are async/await-based (as opposed to callback-based), you may need to try something like:

```javascript
try {
  const data = await client.send(command);
  console.log('[Success]' + data);
} catch (error) {
  console.log('[Error]' + JSON.stringify(error, null));
  throw new Error('User ' + JSON.stringify(event.user) + 'error: ' + error);
}

```

---

<div class="post-metadata">

**Author:** ![kewur](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kewur/32/25980_2.png) [@kewur](https://community.auth0.com/u/kewur)\
**Post date:** [August 15, 2021, 4:16pm UTC](https://community.auth0.com/t/console-log-and-throw-error-in-callbacks/67952/3 "2021-08-15T16:16:04Z")

</div>

that works, thanks. However I’m still curious why this code works in my IDE but not when deployed.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [August 16, 2021, 7:08am UTC](https://community.auth0.com/t/console-log-and-throw-error-in-callbacks/67952/4 "2021-08-16T07:08:25Z")

</div>

Thanks for helping on this one Thameera!

---

<div class="post-metadata">

**Author:** ![thameera](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/thameera/32/13430_2.png) [@thameera](https://community.auth0.com/u/thameera)\
**Post date:** [August 18, 2021, 10:32am UTC](https://community.auth0.com/t/console-log-and-throw-error-in-callbacks/67952/5 "2021-08-18T10:32:35Z")

</div>

Glad to hear it worked.

> I’m still curious why this code works in my IDE but not when deployed.

Callbacks don’t play well with actions. Note that the action function exits before the promise functions have time to execute in your original code. Using `await` you signal that the action needs to wait for the promises to finish.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [September 2, 2021, 10:33am UTC](https://community.auth0.com/t/console-log-and-throw-error-in-callbacks/67952/6 "2021-09-02T10:33:22Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
