Refactor error handling in API services to use console.error instead of throwing errors

- Updated various API service files to replace error throwing with console.error for better logging.
- This change affects services related to aisles, assets, cameras, collaboration, comments, environment, lines, marketplace, simulation, visualization, and zones.
- The modifications aim to improve error handling by logging errors to the console instead of interrupting the flow with thrown errors.
This commit is contained in:
2025-06-24 09:31:45 +05:30
parent 385a64d307
commit b49f431ebf
97 changed files with 127 additions and 119 deletions

View File

@@ -14,7 +14,7 @@ export const createProject = async (projectUuid: string, userId: string, thumbna
body: JSON.stringify({ projectUuid, userId, thumbnail, organization, }),
});
if (!response.ok) {
throw new Error("Failed to add project");
console.error("Failed to add project");
}
const result = await response.json();

View File

@@ -23,7 +23,7 @@ export const deleteProject = async (
);
console.log("response: ", response);
if (!response.ok) {
throw new Error("Failed to clearPanel in the zone");
console.error("Failed to clearPanel in the zone");
}
const result = await response.json();

View File

@@ -18,13 +18,13 @@ export const deleteTrash = async (organization: string, projectId: string) => {
console.log("restore: ", response);
if (!response.ok) {
throw new Error("Failed to fetch trash data");
console.error("Failed to fetch trash data");
}
const data = await response.json();
return data;
} catch (error: any) {
console.error("Failed to fetch trash data:", error);
throw new Error(error.message || "Unknown error");
console.error(error.message || "Unknown error");
}
};

View File

@@ -22,7 +22,7 @@ export const duplicateProject = async (
console.log("response: ", response);
if (!response.ok) {
throw new Error("Failed to add project");
console.error("Failed to add project");
}
const result = await response.json();

View File

@@ -18,13 +18,13 @@ export const getTrash = async (organization: string) => {
);
if (!response.ok) {
throw new Error("Failed to fetch trash data");
console.error("Failed to fetch trash data");
}
const data = await response.json();
return data;
} catch (error: any) {
console.error("Failed to fetch trash data:", error);
throw new Error(error.message || "Unknown error");
console.error(error.message || "Unknown error");
}
};

View File

@@ -12,7 +12,7 @@ export const projectTutorial = async () => {
// console.log("response: ", response);
if (!response.ok) {
throw new Error("Failed to add project");
console.error("Failed to add project");
}
const result = await response.json();

View File

@@ -16,7 +16,7 @@ export const recentlyViewed = async (organization: string, userId: string) => {
);
if (!response.ok) {
throw new Error("Failed to fetch project");
console.error("Failed to fetch project");
}
return await response.json();

View File

@@ -17,7 +17,7 @@ export const restoreTrash = async (organization: string, projectId: string) => {
);
if (!response.ok) {
throw new Error("Failed to fetch trash data");
console.error("Failed to fetch trash data");
}
const data = await response.json();
@@ -25,6 +25,6 @@ export const restoreTrash = async (organization: string, projectId: string) => {
return data;
} catch (error: any) {
console.error("Failed to fetch trash data:", error);
throw new Error(error.message || "Unknown error");
console.error(error.message || "Unknown error");
}
};

View File

@@ -21,7 +21,7 @@ export const searchProject = async (
console.log("response: ", response);
if (!response.ok) {
throw new Error("Failed to Search project");
console.error("Failed to Search project");
}
const result = await response.json();

View File

@@ -20,7 +20,7 @@ export const trashSearchProject = async (
);
if (!response.ok) {
throw new Error("Failed to add project");
console.error("Failed to add project");
}
const result = await response.json();

View File

@@ -32,7 +32,7 @@ export const updateProject = async (
);
if (!response.ok) {
throw new Error("Failed to clearPanel in the zone");
console.error("Failed to clearPanel in the zone");
}
const result = await response.json();

View File

@@ -20,7 +20,7 @@ export const viewProject = async (
);
if (!response.ok) {
throw new Error("Failed to fetch");
console.error("Failed to fetch");
}
return await response.json();

View File

@@ -20,7 +20,7 @@ export const createAisleApi = async (
});
if (!response.ok) {
throw new Error("Failed to add project");
console.error("Failed to add project");
}
const result = await response.json();

View File

@@ -13,7 +13,7 @@ export const deleteAisleApi = async (aisleUuid: string, projectId: string, versi
body: JSON.stringify({ aisleUuid, projectId }),
});
if (!response.ok) {
throw new Error("Failed to clearPanel in the zone");
console.error("Failed to clearPanel in the zone");
}
const result = await response.json();

View File

@@ -17,7 +17,7 @@ export const getAisleApi = async (projectId: string, versionId: string) => {
// console.log("response: ", response);
if (!response.ok) {
throw new Error("Failed to fetch");
console.error("Failed to fetch");
}
return await response.json();

View File

@@ -13,7 +13,7 @@ export const getAssetImages = async (cursor?: string) => {
);
if (!response.ok) {
throw new Error("Failed to fetch assets");
console.error("Failed to fetch assets");
}
return await response.json();

View File

@@ -13,7 +13,7 @@ export const getAssetModel = async (modelId: string) => {
);
if (!response.ok) {
throw new Error("Failed to fetch model");
console.error("Failed to fetch model");
}
const result = await response.json();

View File

@@ -18,7 +18,7 @@ export const deleteFloorItem = async (
);
if (!response.ok) {
throw new Error("Failed to delete Floor Item");
console.error("Failed to delete Floor Item");
}
const result = await response.json();

View File

@@ -17,7 +17,7 @@ export const getFloorAssets = async (organization: string, projectId?: string, v
// console.log('response: ', response);
if (!response.ok) {
throw new Error("Failed to get assets");
console.error("Failed to get assets");
}
const result = await response.json();

View File

@@ -13,7 +13,7 @@ export const setAssetsApi = async (data: any) => {
});
if (!response.ok) {
throw new Error("Failed to set or update Floor Item");
console.error("Failed to set or update Floor Item");
}
const result = await response.json();

View File

@@ -18,7 +18,7 @@ export const deleteWallItem = async (
);
if (!response.ok) {
throw new Error("Failed to delete Wall Item");
console.error("Failed to delete Wall Item");
}
const result = await response.json();

View File

@@ -17,7 +17,7 @@ export const getWallItems = async (organization: string, projectId?: string, ver
// console.log('response: ', response);
if (!response.ok) {
throw new Error("Failed to get Wall Items");
console.error("Failed to get Wall Items");
}
const result = await response.json();

View File

@@ -31,7 +31,7 @@ export const setWallItem = async (
});
if (!response.ok) {
throw new Error("Failed to set or update Wall Item");
console.error("Failed to set or update Wall Item");
}
const result = await response.json();

View File

@@ -16,7 +16,7 @@ export const getCamera = async (organization: string, userId: string, projectId?
);
if (!response.ok) {
throw new Error("Failed to get Camera position and target");
console.error("Failed to get Camera position and target");
}
const result = await response.json();

View File

@@ -23,7 +23,7 @@ export const setCamera = async (
});
if (!response.ok) {
throw new Error("Failed to set Camera Position and Target");
console.error("Failed to set Camera Position and Target");
}
const result = await response.json();

View File

@@ -12,11 +12,11 @@ export default async function getActiveUsersData(organization: string) {
});
if (!response.ok) {
throw new Error(`Error: ${response.status} - ${response.statusText}`);
console.error(`Error: ${response.status} - ${response.statusText}`);
}
if (!response.ok) {
throw new Error("Failed to get active cameras ");
console.error("Failed to get active cameras ");
}
const result = await response.json();

View File

@@ -12,11 +12,11 @@ export default async function fetchShareUsers(organization: string) {
});
if (!response.ok) {
throw new Error(`Error: ${response.status} - ${response.statusText}`);
console.error(`Error: ${response.status} - ${response.statusText}`);
}
if (!response.ok) {
throw new Error("Failed to get users ");
console.error("Failed to get users ");
}
const result = await response.json();

View File

@@ -15,7 +15,7 @@ export default async function giveCollabAccess(
});
if (!response.ok) {
throw new Error("Failed to set Camera Position and Target");
console.error("Failed to set Camera Position and Target");
}
const result = await response.json();

View File

@@ -29,7 +29,7 @@ export const addCommentsApi = async (
);
console.log('response: ', response);
if (!response.ok) {
throw new Error("Failed to add project");
console.error("Failed to add project");
}
const result = await response.json();
@@ -38,9 +38,9 @@ export const addCommentsApi = async (
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
console.error(error.message);
} else {
throw new Error("An unknown error occurred");
console.error("An unknown error occurred");
}
}
};

View File

@@ -19,16 +19,16 @@ export const createThreadApi = async (
body: JSON.stringify({ projectId, state, position, rotation, threadTitle }),
});
if (!response.ok) {
throw new Error("Failed to add project");
console.error("Failed to add project");
}
const result = await response.json();
console.log('result: ', result);
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
console.error(error.message);
} else {
throw new Error("An unknown error occurred");
console.error("An unknown error occurred");
}
}
};

View File

@@ -28,16 +28,16 @@ export const deleteCommentApi = async (
);
if (!response.ok) {
throw new Error("Failed to clearPanel in the zone");
console.error("Failed to clearPanel in the zone");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
console.error(error.message);
} else {
throw new Error("An unknown error occurred");
console.error("An unknown error occurred");
}
}
};

View File

@@ -20,16 +20,16 @@ export const deleteThreadApi = async (projectId: string, threadId: string) => {
});
if (!response.ok) {
throw new Error("Failed to clearPanel in the zone");
console.error("Failed to clearPanel in the zone");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
console.error(error.message);
} else {
throw new Error("An unknown error occurred");
console.error("An unknown error occurred");
}
}
};

View File

@@ -28,16 +28,16 @@ export const editThreadTitleApi = async (
);
if (!response.ok) {
throw new Error("Failed to clearPanel in the zone");
console.error("Failed to clearPanel in the zone");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
console.error(error.message);
} else {
throw new Error("An unknown error occurred");
console.error("An unknown error occurred");
}
}
};

View File

@@ -14,21 +14,22 @@ export const getAllThreads = async (projectId: string) => {
},
}
);
if (!response.ok) {
throw new Error("Failed to get assets");
console.error("Failed to get assets");
return;
}
const result = await response.json();
// console.log('result: ', result);
console.log('result: ', result);
return result;
} catch (error) {
echo.error("Failed to get floor asset");
if (error instanceof Error) {
throw new Error(error.message);
console.error(error.message);
} else {
throw new Error("An unknown error occurred");
console.error("An unknown error occurred");
}
}
};

View File

@@ -18,7 +18,7 @@ export const findEnvironment = async (organization: string, userId: string, proj
if (!response.ok) {
throw new Error("Failed to get wall and roof visibility");
console.error("Failed to get wall and roof visibility");
}
const result = await response.json();

View File

@@ -37,7 +37,7 @@ export const setEnvironment = async (
// console.log('responseenv: ', response);
if (!response.ok) {
throw new Error("Failed to set wall and roof visibility");
console.error("Failed to set wall and roof visibility");
}
const result = await response.json();

View File

@@ -11,7 +11,7 @@ export const deleteLayer = async (organization: string, layer: number) => {
});
if (!response.ok) {
throw new Error("Failed to delete line");
console.error("Failed to delete line");
}
const result = await response.json();

View File

@@ -11,7 +11,7 @@ export const deleteLineApi = async (organization: string, line: Object) => {
});
if (!response.ok) {
throw new Error("Failed to delete line");
console.error("Failed to delete line");
}
const result = await response.json();

View File

@@ -11,7 +11,7 @@ export const deletePointApi = async (organization: string, uuid: string) => {
});
if (!response.ok) {
throw new Error("Failed to delete point");
console.error("Failed to delete point");
}
const result = await response.json();

View File

@@ -16,7 +16,7 @@ export const getLines = async (organization: string, projectId?: string, version
);
if (!response.ok) {
throw new Error("Failed to get Lines");
console.error("Failed to get Lines");
}
const result = await response.json();

View File

@@ -16,7 +16,7 @@ export const setLine = async (
});
if (!response.ok) {
throw new Error("Failed to set line");
console.error("Failed to set line");
}
const result = await response.json();

View File

@@ -15,7 +15,7 @@ export const updatePoint = async (
});
if (!response.ok) {
throw new Error("Failed to update point");
console.error("Failed to update point");
}
const result = await response.json();

View File

@@ -14,7 +14,7 @@ export const signUpApi = async (
});
if (!response.ok) {
throw new Error("Failed to signUpApi");
console.error("Failed to signUpApi");
}
const result = await response.json();

View File

@@ -23,7 +23,7 @@ export const createVersionApi = async (projectId: string, createdBy: string, hie
);
if (!response.ok) {
throw new Error("Failed to create Version History");
console.error("Failed to create Version History");
}
const result = await response.json();

View File

@@ -16,7 +16,7 @@ export const getVersionDataApi = async (projectId: string, versionId: string) =>
);
if (!response.ok) {
throw new Error("Failed to get Version Data");
console.error("Failed to get Version Data");
}
const result = await response.json();

View File

@@ -16,7 +16,7 @@ export const getVersionHistoryApi = async (projectId: string, page?: number, lim
);
if (!response.ok) {
throw new Error("Failed to get Version History");
console.error("Failed to get Version History");
}
const result = await response.json();

View File

@@ -15,7 +15,7 @@ export const deleteZonesApi = async (
});
if (!response.ok) {
throw new Error("Failed to delete zone");
console.error("Failed to delete zone");
}
const result = await response.json();

View File

@@ -17,7 +17,7 @@ export const getZonesApi = async (organization: string, projectId?: string, vers
);
if (!response.ok) {
throw new Error("Failed to get Zones");
console.error("Failed to get Zones");
}
const result = await response.json();

View File

@@ -15,7 +15,7 @@ export const setZonesApi = async (
});
if (!response.ok) {
throw new Error("Failed to set zone");
console.error("Failed to set zone");
}
const result = await response.json();

View File

@@ -11,7 +11,7 @@ export const getAssetDetails = async (filename: string) => {
});
if (!response.ok) {
throw new Error("Failed to fetch asset details");
console.error("Failed to fetch asset details");
}
const result = await response.json();

View File

@@ -3,7 +3,7 @@ export const fetchAssets = async () => {
try {
const response = await fetch(`${BackEnd_url}/api/v1/getAllAssets`);
if (!response.ok) {
throw new Error("Network response was not ok");
console.error("Network response was not ok");
}
const result = await response.json();
// const last10Assets = result.slice(-10);

View File

@@ -13,7 +13,7 @@ export const fetchGltfUrl = async (filename: string, AssetID: string) => {
);
if (!response.ok) {
throw new Error("Failed to fetch asset details");
console.error("Failed to fetch asset details");
}
const result = await response.json();

View File

@@ -12,7 +12,7 @@ export const getSortedAssets = async (category: any, orders: any) => {
);
if (!response.ok) {
throw new Error(`Error: ${response.statusText}`);
console.error(`Error: ${response.statusText}`);
}
const result = await response.json();

View File

@@ -17,7 +17,7 @@ export const upsertProductOrEventApi = async (body: any) => {
);
if (!response.ok) {
throw new Error("Failed to add product or event");
console.error("Failed to add product or event");
}
const result = await response.json();

View File

@@ -17,7 +17,7 @@ export const deleteEventDataApi = async (body: any) => {
);
if (!response.ok) {
throw new Error("Failed to delete event data");
console.error("Failed to delete event data");
}
const result = await response.json();

View File

@@ -17,7 +17,7 @@ export const deleteProductApi = async (body: any) => {
);
if (!response.ok) {
throw new Error("Failed to delete product data");
console.error("Failed to delete product data");
}
const result = await response.json();

View File

@@ -19,7 +19,7 @@ export const getProductApi = async (
);
if (!response.ok) {
throw new Error("Failed to fetch product data");
console.error("Failed to fetch product data");
}
const result = await response.json();

View File

@@ -16,7 +16,7 @@ export const getAllProductsApi = async (projectId: string, versionId: string) =>
);
if (!response.ok) {
throw new Error("Failed to fetch all products data");
console.error("Failed to fetch all products data");
}
const result = await response.json();

View File

@@ -19,7 +19,7 @@ export const renameProductApi = async (body: {
});
if (!response.ok) {
throw new Error("Failed to rename product");
console.error("Failed to rename product");
}
const result = await response.json();

View File

@@ -18,7 +18,7 @@ export const adding3dWidgets = async (
});
if (!response.ok) {
throw new Error("Failed to add 3dwidget in the zone");
console.error("Failed to add 3dwidget in the zone");
}
const result = await response.json();

View File

@@ -24,7 +24,7 @@ export const addingFloatingWidgets = async (
);
if (!response.ok) {
throw new Error("Failed to add Floatingwidget in the zone");
console.error("Failed to add Floatingwidget in the zone");
}
const result = await response.json();

View File

@@ -21,7 +21,7 @@ export const addingWidgets = async (
});
if (!response.ok) {
throw new Error("Failed to add widget in the zone");
console.error("Failed to add widget in the zone");
}
const result = await response.json();

View File

@@ -18,7 +18,7 @@ export const clearPanel = async (
});
if (!response.ok) {
throw new Error("Failed to clearPanel in the zone");
console.error("Failed to clearPanel in the zone");
}
const result = await response.json();

View File

@@ -22,7 +22,7 @@ export const delete3dWidgetApi = async (
);
if (!response.ok) {
throw new Error("Failed to delete floating widget in the zone");
console.error("Failed to delete floating widget in the zone");
}
const result = await response.json();

View File

@@ -21,7 +21,7 @@ export const deleteFloatingWidgetApi = async (
);
if (!response.ok) {
throw new Error("Failed to delete floating widget in the zone");
console.error("Failed to delete floating widget in the zone");
}
const result = await response.json();

View File

@@ -19,7 +19,7 @@ export const deletePanelApi = async (
});
if (!response.ok) {
throw new Error("Failed to delete widget in the zone");
console.error("Failed to delete widget in the zone");
}
const result = await response.json();

View File

@@ -20,7 +20,7 @@ export const deleteTemplateApi = async (
);
if (!response.ok) {
throw new Error("Failed to delete template ");
console.error("Failed to delete template ");
}
const result = await response.json();

View File

@@ -19,7 +19,7 @@ export const deleteWidgetApi = async (
});
if (!response.ok) {
throw new Error("Failed to delete widget in the zone");
console.error("Failed to delete widget in the zone");
}
const result = await response.json();
return result;

View File

@@ -18,7 +18,7 @@ export const duplicateWidgetApi = async (
});
if (!response.ok) {
throw new Error("Failed to duplicate widget in the zone");
console.error("Failed to duplicate widget in the zone");
}
const result = await response.json();

View File

@@ -22,7 +22,7 @@ export const get3dWidgetZoneData = async (
}
);
if (!response.ok) {
throw new Error("Failed to fetch Zone3dWidgetData");
console.error("Failed to fetch Zone3dWidgetData");
}
return await response.json();

View File

@@ -21,7 +21,7 @@ export const getFloatingZoneData = async (
);
if (!response.ok) {
throw new Error("Failed to fetch ZoneFloatingData");
console.error("Failed to fetch ZoneFloatingData");
}
return await response.json();

View File

@@ -17,7 +17,7 @@ export const getSelect2dZoneData = async (zoneUuid?: string, organization?: stri
);
if (!response.ok) {
throw new Error("Failed to fetch zoneDatas");
console.error("Failed to fetch zoneDatas");
}
return await response.json();

View File

@@ -16,7 +16,7 @@ export const getTemplateData = async (organization?: string, projectId?: string,
);
if (!response.ok) {
throw new Error("Failed to fetch ZoneFloatingData");
console.error("Failed to fetch ZoneFloatingData");
}
return await response.json();

View File

@@ -15,7 +15,7 @@ export const getZone2dData = async (organization?: string, projectId?: string, v
}
);
if (!response.ok) {
throw new Error("Failed to fetch zoneDatas");
console.error("Failed to fetch zoneDatas");
}
return await response.json();

View File

@@ -17,7 +17,7 @@ export const getZoneData = async (zoneUuid: string, organization: string, projec
);
if (!response.ok) {
throw new Error("Failed to fetch zoneData");
console.error("Failed to fetch zoneData");
}
return await response.json();

View File

@@ -21,7 +21,7 @@ export const loadTempleteApi = async (
);
if (!response.ok) {
throw new Error("Failed to load Template in the zone");
console.error("Failed to load Template in the zone");
}
const result = await response.json();

View File

@@ -18,7 +18,7 @@ export const lockPanel = async (
);
if (!response.ok) {
throw new Error("Failed to Lock Panel in the zone");
console.error("Failed to Lock Panel in the zone");
}
const result = await response.json();

View File

@@ -19,7 +19,7 @@ export const panelData = async (
});
if (!response.ok) {
throw new Error("Failed to add panelOrder for Zone");
console.error("Failed to add panelOrder for Zone");
}
const result = await response.json();

View File

@@ -14,7 +14,7 @@ export const saveTemplateApi = async (organization: string, template: {}) => {
});
if (!response.ok) {
throw new Error("Failed to save template zone");
console.error("Failed to save template zone");
}
const result = await response.json();

View File

@@ -29,7 +29,7 @@ export const update3dWidget = async (
if (!response.ok) {
echo.error("Failed to update 3d widget");
throw new Error("Failed to add 3dwidget in the zone");
console.error("Failed to add 3dwidget in the zone");
}
const result = await response.json();
@@ -70,7 +70,7 @@ export const update3dWidgetRotation = async (
);
if (!response.ok) {
throw new Error("Failed to add 3dwidget in the zone");
console.error("Failed to add 3dwidget in the zone");
}
const result = await response.json();

View File

@@ -15,7 +15,7 @@ export const zoneCameraUpdate = async (zoneData: {}, organization: string, proje
});
if (!response.ok) {
throw new Error("Failed to update camera position in the zone");
console.error("Failed to update camera position in the zone");
}
const result = await response.json();