Reputation: 315
I'm using a third party Javascript API for displaying seatmaps for flights in our website.
I'm not an expert in Javascript and have some trouble understanding promises in Javascript.
So I have this function that I call to save the seats selected by user.
seatmap
.save(jsondata)
.then(
function (result)
{
console.log("Save");
SaveSeats();
},
function(error)
{
console.log("Error");
ErrorHandling();
});
Whenever the API returns a 500 Internal Server Error it doesnot go inside the error function. According to my understanding if the function results in an error it should go to function(error).
Please let me know the best way to do this.Since I have to create live bookings to test this,I'm not supposed to test this many times.
Upvotes: 0
Views: 85
Reputation: 943696
The function passed to new Promise(function_goes_here)
gets two arguments. resolve
and reject
. The values of these arguments are functions.
If reject
gets called, then the error function you pass to then()
gets called.
It is the responsibility of the code inside seatmap.save
to call reject
(or otherwise expose the error to you) if there is a 500
error.
Upvotes: 3