How do I handle the addTask errors?
I notice that even if the api is down, and addTask request failed, the task is added successfully in the clinet, that’s misleading.
thank you
How do I handle the addTask errors?
I notice that even if the api is down, and addTask request failed, the task is added successfully in the clinet, that’s misleading.
thank you
Hello,
To handle errors that occur during the task addition process, you can utilize the onAfterUpdate
event handler provided by the DataProcessor. You can refer to the documentation for more details on error handling: Server-Side Integration Gantt Docs.
To specifically handle the creation of tasks, you can add an isCreatingTask
flag and define it within the onBeforeTaskAdd
handler. Here’s an example:
let isCreatingTask = null;
gantt.attachEvent("onBeforeTaskAdd", (id, item) => {
isCreatingTask = true;
return true;
});
const dp = gantt.createDataProcessor({
url: server,
mode: "REST"
});
dp.attachEvent("onAfterUpdate", (id, action, tid, response) => {
if (action == "error" && isCreatingTask) {
gantt.deleteTask(id);
};
isCreatingTask = false;
});
If the server returns an error during the task creation process, the gantt.deleteTask
method can be used to remove the task from the client-side.
what if the server is down? is there a way to add a ajax onerror handler
You can handle AJAX errors by utilizing the onAjaxError
:
let createdTaskId = null;
gantt.attachEvent("onBeforeTaskAdd", (id, item) => {
createdTaskId = id;
return true;
});
gantt.attachEvent("onAjaxError", function(request) {
gantt.message({type: "error", text: `Http error ${request.status}!`});
gantt.message(request.response);
if (createdTaskId) {
dp.ignore(() => {
gantt.deleteTask(createdTaskId);
});
createdTaskId = false;
}
return true;
});
Thanks! That will do