Browse Source

Improve error handling

pull/1/head
Wahyu Ramadhan 1 year ago
parent
commit
302e428b2b
  1. 26
      edit-mode/function/reportActivity.js

26
edit-mode/function/reportActivity.js

@ -418,34 +418,32 @@ $(document).ready(function () {
} }
async function submitRaMaterial(formData, id) { async function submitRaMaterial(formData, id) {
let qty_actual = $("#volume_pekerjaan_material").val(); try {
const qty_actual = $("#volume_pekerjaan_material").val();
formData.set('qty', qty_actual); formData.set('qty', qty_actual);
const result = await axiosInstance const result = await axiosInstance
.post(`${base_url}report-activity-material/add`, formData) .post(`${base_url}report-activity-material/add`, formData);
.then(res => res)
.catch((error) => error.response);
// console.log("cek result", result); const reportId = result.data.data.report_id;
let reportId = result.data.data.report_id; const image = formData.get("files");
let imageFormData = new FormData(); const imageFormData = new FormData();
let image = formData.get("files");
imageFormData.append("ref_id", reportId); imageFormData.append("ref_id", reportId);
imageFormData.append("category", "report_activity"); imageFormData.append("category", "report_activity");
imageFormData.append("files", image, image.name); imageFormData.append("files", image, image.name);
const resultImage = await axiosInstanceMultipart const resultImage = await axiosInstanceMultipart.post(`${base_url}image/upload`, imageFormData);
.post(`${base_url}image/upload`, imageFormData)
.then(res => res)
.catch((error) => error.response);
if (result && result.status == 200 && resultImage && resultImage.status == 200) { if (result.status === 200 && resultImage.status === 200) {
gantt.alert("Add report activity material Success!"); gantt.alert("Add report activity material Success!");
resetFormAddRaMaterial(); resetFormAddRaMaterial();
tableRaMaterialActual.draw(); tableRaMaterialActual.draw();
} else { } else {
throw new Error("Add report activity material failed.");
}
} catch (error) {
resetFormAddRaMaterial(); resetFormAddRaMaterial();
$("body").removeClass("loading"); $("body").removeClass("loading");
gantt.alert("Add report activity material failed, try again later!"); gantt.alert("Add report activity material failed.");
} }
} }

Loading…
Cancel
Save