#query alerts

1 messages · Page 1 of 1 (latest)

pearl gull
#

I want to show alert when query fails and when it succesfully completes.

I thought it would with code like this, but it doesnt:

async DeleteAStop (){
await storeValue("CurrentStop", StopsList.triggeredItem);
delete_stop.run(() => {
if (delete_stop.data.code === 400) {
showAlert("Bad request!", "error");
} else if (delete_stop.data.code === 401) {
showAlert("Unauthorized, please log in!", "error");
} else if (delete_stop.data.code === 403) {
showAlert(delete_stop.data.message, "error");
} else {
showAlert(delete_stop.data, "error");
}
});
get_stops.run();
}

coral blazeBOT
#

Hello! I'm AppyBuilder, your support bot for all things Appsmith. Let's
troubleshoot the issue you're having with showing alerts upon query execution.
The function you provided seems to be an asynchronous JavaScript function to
delete a stop and show alerts based on the response status code. However,
Appsmith has its own way of handling such logic. To handle success and error
responses, you can use the .then() method for success and the .catch()
method for errors. Here's how you can modify your function to show alerts on
success and failure: async function DeleteAStop() { await storeValue("CurrentStop", StopsList.triggeredItem); delete_stop.run() .then((response) => { // Handle successful deletion showAlert("Stop deleted successfully!", "success"); get_stops.run(); }) .catch((error) => { // Handle errors, error.code contains the status code if (error.code === 400) { showAlert("Bad request!", "error"); } else if (error.code === 401) { showAlert("Unauthorized, please log in!", "error"); } else if (error.code === 403) { showAlert("Forbidden access!", "error"); } else { showAlert("An unexpected error occurred!", "error"); } }); } This updated function
performs the delete operation and shows an alert if it's successful or if
there's an error. The .run() method returns a promise, so you can attach
.then() and .catch() callbacks to handle the resolved value or errors,
respectively. You can replace the success and error messages with appropriate
messages as per your application's context. Remember to call this function when
you want to perform the deletion action. Please test this updated function and
let me know if there's anything else I can help with! If you don't find my
response helpful, you can request to speak to a human agent

coral blazeBOT
#

Are you still facing the issue?