Refactor API service functions for improved error handling and code consistency
- Updated signUpApi, deleteZonesApi, getZonesApi, setZonesApi, and other API functions to enhance error logging with echo.error statements. - Reformatted function parameters for better readability. - Removed unnecessary comments and console logs. - Ensured consistent error messages across all API functions. - Improved code structure for better maintainability.
This commit is contained in:
@@ -6,13 +6,16 @@ export const lockPanel = async (
|
||||
lockedPanel: any
|
||||
) => {
|
||||
try {
|
||||
const response = await fetch(`${url_Backend_dwinzo}/api/v2/zones/lockedPanels`, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ organization, zoneId, lockedPanel }),
|
||||
});
|
||||
const response = await fetch(
|
||||
`${url_Backend_dwinzo}/api/v2/zones/lockedPanels`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ organization, zoneId, lockedPanel }),
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to Lock Panel in the zone");
|
||||
@@ -21,10 +24,11 @@ export const lockPanel = async (
|
||||
const result = await response.json();
|
||||
return result;
|
||||
} catch (error) {
|
||||
echo.error("Failed to fetch locked panel data");
|
||||
if (error instanceof Error) {
|
||||
throw new Error(error.message);
|
||||
} else {
|
||||
throw new Error("An unknown error occurred");
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user