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

586
Views
NODE.JS: How to have front-end JS event listener for when there is a back-end error on form submit?

Using Node.js, I have a form that uses twilio to send an SMS. Everything works fine testing it with my phone.

However, I would like to have an animation play (in my front-end JS file) if the form submit encounters an error in the back-end. Specifically, the twilio API has a callback that takes an error as an argument with the sendMessage function. So I'm not talking about validation errors, but actual errors with twilio or the connection.

So how do I have an event listener in my front-end js files to listen for when there is an error in the callback function of submitting the form (in the back-end) so I can play an animation expressing something went wrong.

Or should I not use event listeners and do it another way?

Any help appreciated. Please respond. Thank you!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No you cannot add an event listener in the front-end for an error in the back end. That is not possible.

If using a HTML form without AJAX:

Now you are using the default HTML form and using the action and method attributes to submit the form data. Then the process will be similar to what you do with error handling. You submit the data then proceed with your interaction with Twillo API. If something fails you redirect the user to the form page with the error message/error animation.

If using AJAX:

Now as you are using AJAX you must have the ability to handle the response you get from the server. In this process when the user submits data the back-end proceeds with the interaction with Twillo API. If something fails you send back an 500 Internal Server Error with the proper error message. In the AJAX request callback you check the response code and error message. If something is wrong you can now play the error animation/let the user know about what happened.

Resources: https://nodejs.org/api/synopsis.html Check the example in this link. It is shown how to set statuscode for the response.

over 4 years ago · Santiago Trujillo Report
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!