Browse Source

Improve error handling

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

50
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 {
formData.set('qty', qty_actual); const qty_actual = $("#volume_pekerjaan_material").val();
const result = await axiosInstance formData.set('qty', qty_actual);
.post(`${base_url}report-activity-material/add`, formData) const result = await axiosInstance
.then(res => res) .post(`${base_url}report-activity-material/add`, formData);
.catch((error) => error.response);
const reportId = result.data.data.report_id;
// console.log("cek result", result); const image = formData.get("files");
let reportId = result.data.data.report_id; const imageFormData = new FormData();
let imageFormData = new FormData(); imageFormData.append("ref_id", reportId);
let image = formData.get("files"); imageFormData.append("category", "report_activity");
imageFormData.append("ref_id",reportId); imageFormData.append("files", image, image.name);
imageFormData.append("category", "report_activity");
imageFormData.append("files", image, image.name); const resultImage = await axiosInstanceMultipart.post(`${base_url}image/upload`, imageFormData);
const resultImage = await axiosInstanceMultipart if (result.status === 200 && resultImage.status === 200) {
.post(`${base_url}image/upload`, imageFormData) gantt.alert("Add report activity material Success!");
.then(res => res) resetFormAddRaMaterial();
.catch((error) => error.response); tableRaMaterialActual.draw();
} else {
if (result && result.status == 200 && resultImage && resultImage.status == 200) { throw new Error("Add report activity material failed.");
gantt.alert("Add report activity material Success!"); }
resetFormAddRaMaterial(); } catch (error) {
tableRaMaterialActual.draw();
} else {
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