Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
Is not awaiting certain promises wrong?

Using express I have one REST route where I fetch some data. Within this request I also add an entry into an event table (for app insights purposes) in the database. I do not really care to wait for that event to be saved before returning the actual data to the requester, since saving the event is not that important for the end user.

Something like this pseudo code:

const data = await getResponseDataFromDatabase();

insertInsightsEventIntoDatabase(); // returns a promise which I don't want to wait for

return data;

Since there was a bug in the insertInsightsEventIntoDatabase I got this error in the logs:

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(). The promise rejected with the reason:
Error: Cannot set headers after they are sent to the client

If I await the insertInsightsEventIntoDatabase() I would get a much better error log in the console that shows an error from the ORM I am using.

My question is, it it wrong to not await the method? I like the idea of not awaiting it just to have it "run in the background" and not blocking the time it takes to send the response on the client request. The drawback is that the real error seems to be swallowed and I would very much like to have the original error in the logs.

Am I doing this wrong?

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!