---
title: "Comment by M. Suman Patra on \"6 Common mistakes in using JavaScript Promises\" | Hashnode"
description: "Really Nice article !! I will take this opportunity to clear my doubts. I code as per below. const request = require ( &#x27;request&#x27; ); const test = userD"
url: "https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/6149707517da986cea648e81"
---

[Discussion](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580)

Comment [6 Common mistakes in using JavaScript Promises](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580)

[M. Suman Patra](https://hashnode.com/@msuman)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/6149707517da986cea648e81)

**Really Nice article !!**

I will take this opportunity to clear my doubts. I code as per below.

```
const request = require('request');
const test = userData => {
  console.log('test::parameters', userData);
  if (userData && userData.request === true) {
    const option = {
      method: 'POST',
      url: 'jsonplaceholder.typicode.com/posts&,
      headers: {
        'Content-type': 'application/json; charset=UTF-8'
      },
      json: true,
      proxy: null,
      body: {
        title: 'foo',
        body: 'bar',
        userId: 1
      }
    };
    console.log('test::outgoingBody::', option);
    return new Promise((resolve, reject) => {
      request(option, (error, response) => {
        if (error) {
          return reject(error);
        } else {
          if (response && response.body ) {
            return resolve();
          } else {
            return reject(new Error('Error Response'));
          }
        }
      });
    });
  } else {
    return Promise.reject(new Error('Invalid Userdata'));
  }
};
//some business logics
test().catch(err=>console.error(err))
//some business logics
//--------------------------
//some business logics
test({request:true}).catch(err=>console.error(err))
//some business logics
```

1.  As I am not returning anything from test function, I don't use then callback.
2.  I use Promise.reject to throw any synchronous error.

Am I doing correctly?

[Tapas Adhikary](https://hashnode.com/@atapas)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/6149707517da986cea648e81#reply-61497dae17da986cea648fe2)

[M. Suman Patra](https://hashnode.com/@msuman), Thanks for reading and feedback.

-   You can use `Promise.reject` to throw the error. That's right.
-   However when you say, you are not returning anything, I see you are returning a promise in the case userdata request is `true`. So to handle that promise's resolve you should have a `.then()`. Why did you think, you are not returning anything?

[M. Suman Patra](https://hashnode.com/@msuman)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/6149707517da986cea648e81#reply-6149893617da986cea649165)

[Tapas Adhikary](https://hashnode.com/@atapas), To catch test function errors gracefully, I am using catch callback but I thought then callback is not needed because I am not waiting for test function execution and also not returning anything from API call/from the test function.

Note: As the request dependency does not support async/await, I had to use promise constructor.

[Tapas Adhikary](https://hashnode.com/@atapas)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/6149707517da986cea648e81#reply-61499129699fe76cd3485c6f)

[M. Suman Patra](https://hashnode.com/@msuman), I get that. In your typical case, where you do not return anything by resolving the promise, you are not accountable for handling it.

```
if (response && response.body ) {
     return resolve();
}
```

So, the current handling works to take care of the error test cases alone. If that's what is the intention, it looks good to me.

[M. Suman Patra](https://hashnode.com/@msuman)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/6149707517da986cea648e81#reply-614991c817da986cea64927a)

[Tapas Adhikary](https://hashnode.com/@atapas), Thanks for the info and will be waiting for ur next youtube video.
