title: unhandledRejection nodejs
body: <p>I know there's quite a lot of posts about this error, most of them have the same answer but somehow I am still getting the warning.</p>
  
  <p>I have read something like this <a href="https://stackoverflow.com/questions/40515161/in-node-js-7-what-is-the-proper-way-to-suppress-unhandledpromiserejectionwarning">In Node.js 7 what is the proper way to suppress UnhandledPromiseRejectionWarning?</a> but instead of <code>on</code> I use <code>once</code> because of the event listener leak but somehow I still see the warning sometimes</p>
  
  <p>I do want to get ride of the warning or solve it since its saying deprecated in the future but not sure when.</p>
  
  <p>At first when I first run I would get this first</p>
  
  <p><code>You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection: myrejectionmessage
  </code></p>
  
  <p>then after, I will get this error </p>
  
  <p><code>UnhandledPromiseRejectionWarning: myrejectionmessage</code>
  <code>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: 5)</code></p>
  
  <p>this is my original code without what I tried with the posts I found, I am trying to get some files in <code>aws s3 bucket</code> but there is possible that the file in bucket does not exist</p>
  
  <p>this function is to compare if there is file then compare the modified time, if the file does not exist <code>reject</code></p>
  
  <pre><code>exports.compareObjectMT = (s3, Key, getFileStat) =&gt; {
      const s3GetParams = {
          Bucket: process.env.S3_BUCKET,
          Key,
      };
  
      return new Promise((res, rej) =&gt; {
          s3.getObject(s3GetParams, (err, data) =&gt; {
              if (err) rej('myrejecterror');
              if (data) {
                  res(String(getFileStat.mtimeMs) === data.Metadata.mtimems);
              }
              res(false);
          });
      });
  };
  </code></pre>
  
  <p>Thanks in advance for any suggestions</p>
  
  <p>This is how I am using the function</p>
  
  <pre><code>exports.s3Put = async (path) =&gt; {
      try {
          fs.readFile(path, async (err, fileBinary) =&gt; {
              if (err) throw err;
              // console.log(data, 'data');
              const s3 = new AWS.S3();
              const Key = path.replace(process.env.WATCH_PATH, '');
              const getStat = await getFileStat(path);
              console.log(getStat, 'getstateeeeeeeeeeeeeeee');
              const compareObj = await compareObjectMT(s3, Key, getStat);
              console.log(compareObj, 'compareObj');
          });
      } catch (e) {
          console.log(e, 'errorrrrrrrrrrrrr');
      }
  };
  </code></pre>