diff --git a/backend/src/routes/driver.ts b/backend/src/routes/driver.ts index 9b6ad03..5c8e56a 100644 --- a/backend/src/routes/driver.ts +++ b/backend/src/routes/driver.ts @@ -67,7 +67,6 @@ router.get("/get", async (req: Request, res: Response) => { res.json(drivers); } catch (error) { const errorMessage = (error as Error).message; - console.error("Error fetching drivers:", errorMessage); // Log the error for debugging res.status(500).json({ title: "Unknown Error", message: errorMessage }); } }); @@ -192,7 +191,6 @@ router.delete("/delete", async (req: Request, res: Response) => { const { id } = req.body; if (!id) { - console.error("No ID provided in the request body"); res.status(400).json({ title: "Validation Error", message: "Driver ID is required to delete a record.", @@ -210,7 +208,6 @@ router.delete("/delete", async (req: Request, res: Response) => { ); if (resultDriver.rowCount === 0) { - console.error("Driver not found in the database"); res.status(404).json({ title: "Not Found", message: "Driver with the specified ID does not exist.", diff --git a/backend/src/routes/notification.ts b/backend/src/routes/notification.ts index 6533f36..2dcdbbe 100644 --- a/backend/src/routes/notification.ts +++ b/backend/src/routes/notification.ts @@ -70,8 +70,7 @@ router.post("/add", async (req: Req, res: Response) => { title: "Notification Sent", message: "Notification has been sent successfully.", }); - } catch (err) { - console.error("ERROR", err); + } catch { res .status(500) .json({ error: "An error occurred while creating notification." }); @@ -94,8 +93,7 @@ router.delete("/delete", async (req: Req, res: Response) => { message: "Notification successfully deleted.", }); } - } catch (err) { - console.error(err); + } catch { res .status(500) .json({ message: "An error occurred while deleting the notification." }); diff --git a/backend/src/routes/registration.ts b/backend/src/routes/registration.ts index c770bd9..1ed6278 100644 --- a/backend/src/routes/registration.ts +++ b/backend/src/routes/registration.ts @@ -23,7 +23,6 @@ router.get("/get", async (_req: Request, res: Response) => { res.json(registrations); // Send the registration list as a response } catch (error) { const errorMessage = (error as Error).message; - console.error("Error fetching registration list:", errorMessage); res.status(500).json({ title: "Unknown Error", message: errorMessage }); } }); @@ -86,10 +85,8 @@ router.post("/add", async (req: Request, res: Response) => { }); } catch (error) { if (error instanceof Error) { - console.error("Error occurred:", error.message); res.status(500).json({ title: "Server Error", message: error.message }); } else { - console.error("Unexpected error occurred:", error); res.status(500).json({ title: "Server Error", message: "An unexpected error occurred.", @@ -114,8 +111,7 @@ router.delete("/delete", async (req: Request, res: Response): Promise => { title: "Registration Deleted", message: `Registration with license number ${license_number} has been successfully deleted.`, }); - } catch (error) { - console.error("Error occurred during deletion:", error); + } catch { res.status(500).json({ success: false, title: "Server Error", @@ -208,7 +204,6 @@ router.post("/approve", async (req: Request, res: Response) => { } } catch (error) { await client.query("ROLLBACK"); - console.error("Error during approval process:", (error as Error).message); res .status(500) .json({ title: "Server Error", message: (error as Error).message }); diff --git a/backend/src/routes/user.ts b/backend/src/routes/user.ts index 192d4ea..9a3fd22 100644 --- a/backend/src/routes/user.ts +++ b/backend/src/routes/user.ts @@ -30,9 +30,7 @@ router.get("/get", async (req: Request, res: Response) => { isDriver: drivers[0] ? true : false, }); // Send the user data as a response } catch (error) { - console.error(error); const errorMessage = (error as Error).message; - console.error("Error fetching the user:", errorMessage); res.status(500).json({ title: "Unknown Error", message: errorMessage }); } }); diff --git a/backend/src/routes/violation.ts b/backend/src/routes/violation.ts index 4bc33c6..544fd36 100644 --- a/backend/src/routes/violation.ts +++ b/backend/src/routes/violation.ts @@ -46,7 +46,6 @@ router.post("/add", async (req: Request, res: Response) => { }); } catch (error) { const errorMessage = (error as Error).message; - console.error("Error:", errorMessage); res.status(500).json({ title: "Error", message: errorMessage }); } }); diff --git a/frontend/src/hooks/car-hooks/useAddCar.ts b/frontend/src/hooks/car-hooks/useAddCar.ts index a572474..84d01a3 100644 --- a/frontend/src/hooks/car-hooks/useAddCar.ts +++ b/frontend/src/hooks/car-hooks/useAddCar.ts @@ -24,7 +24,6 @@ const useAddCar = () => { if (!response.ok) { const errorData = await response.json(); - console.error("Error response from server:", errorData); // Log server response toast.error(errorData.message); return; } diff --git a/frontend/src/hooks/car-hooks/useCheckLicenseNumber.ts b/frontend/src/hooks/car-hooks/useCheckLicenseNumber.ts index 8b6acb5..d07d0c7 100644 --- a/frontend/src/hooks/car-hooks/useCheckLicenseNumber.ts +++ b/frontend/src/hooks/car-hooks/useCheckLicenseNumber.ts @@ -36,8 +36,7 @@ const useCheckLicenseNumber = () => { const driver = await response.json(); return driver; - } catch (error) { - console.error("Error checking license number:", error); + } catch { toast.error("Failed to verify license number."); return; } finally { diff --git a/frontend/src/hooks/car-hooks/useDeleteCar.ts b/frontend/src/hooks/car-hooks/useDeleteCar.ts index 29b3761..608c582 100644 --- a/frontend/src/hooks/car-hooks/useDeleteCar.ts +++ b/frontend/src/hooks/car-hooks/useDeleteCar.ts @@ -22,10 +22,7 @@ export const useDeleteCar = () => { if (!response.ok) { const errorData = await response.json(); - console.error("Error response from server:", errorData); // Log server response - toast.error(errorData.message); - return; } @@ -34,10 +31,8 @@ export const useDeleteCar = () => { return; } catch (err: unknown) { - console.error("Network error:", err); - // Narrow down `err` to ensure it has a `message` property - const errorMessage = + const errorMessage = err instanceof Error ? err.message : "Failed to connect to the server"; toast.error(errorMessage); diff --git a/frontend/src/hooks/car-hooks/useEditCars.ts b/frontend/src/hooks/car-hooks/useEditCars.ts index 72b203e..65d86a9 100644 --- a/frontend/src/hooks/car-hooks/useEditCars.ts +++ b/frontend/src/hooks/car-hooks/useEditCars.ts @@ -24,7 +24,6 @@ const useEditCar = () => { if (!response.ok) { const errorData = await response.json(); - console.error("Error response from server:", errorData); // Log server response toast.error(errorData.message); return; } diff --git a/frontend/src/hooks/driver-hooks/useAddDriver.ts b/frontend/src/hooks/driver-hooks/useAddDriver.ts index 5bd516b..58080cd 100644 --- a/frontend/src/hooks/driver-hooks/useAddDriver.ts +++ b/frontend/src/hooks/driver-hooks/useAddDriver.ts @@ -27,8 +27,7 @@ export const useAddDriver = () => { const error: BackendMessage = await response.json(); setError(error); } - } catch (error) { - console.error("Unexpected error:", error); + } catch { setError({ message: "An unexpected error occurred" } as BackendMessage); } finally { setTimeout(() => { diff --git a/frontend/src/hooks/driver-hooks/useDeleteDriver.ts b/frontend/src/hooks/driver-hooks/useDeleteDriver.ts index 080bb7d..d2575be 100644 --- a/frontend/src/hooks/driver-hooks/useDeleteDriver.ts +++ b/frontend/src/hooks/driver-hooks/useDeleteDriver.ts @@ -22,7 +22,6 @@ export const useDeleteDriver = () => { if (!response.ok) { const errorData = await response.json(); - console.error("Error response from server:", errorData); // Log server response toast.error(errorData.message); return; } diff --git a/frontend/src/hooks/driver-hooks/useDrivers.ts b/frontend/src/hooks/driver-hooks/useDrivers.ts index 9bf111d..eb85f25 100644 --- a/frontend/src/hooks/driver-hooks/useDrivers.ts +++ b/frontend/src/hooks/driver-hooks/useDrivers.ts @@ -28,8 +28,7 @@ const useDrivers = () => { const drivers: DriverWithVandC[] = await response.json(); setData(drivers); } - } catch (err) { - console.error("Unexpected error:", err); + } catch { setError({ message: "An unexpected error occurred" } as BackendMessage); } finally { setLoading(false); diff --git a/frontend/src/hooks/registration-hooks/useApproveRegistration.ts b/frontend/src/hooks/registration-hooks/useApproveRegistration.ts index 4d89e1d..cc5f93f 100644 --- a/frontend/src/hooks/registration-hooks/useApproveRegistration.ts +++ b/frontend/src/hooks/registration-hooks/useApproveRegistration.ts @@ -34,8 +34,7 @@ export const useApproveRegistration = () => { const data = await response.json(); toast.success(data.message || "Registration approved successfully!"); - } catch (error) { - console.error("Error approving registration:", error); + } catch { toast.error( "Network error occurred. Could not connect to the server. Please try again.", ); diff --git a/frontend/src/hooks/registration-hooks/useDeleteRegistration.ts b/frontend/src/hooks/registration-hooks/useDeleteRegistration.ts index 75ca81c..d0743f6 100644 --- a/frontend/src/hooks/registration-hooks/useDeleteRegistration.ts +++ b/frontend/src/hooks/registration-hooks/useDeleteRegistration.ts @@ -30,8 +30,7 @@ export const useDeleteRegistration = () => { let responseBody; try { responseBody = await response.json(); - } catch (error) { - console.error("Failed to parse JSON response:", error); + } catch { throw new Error("Invalid JSON response from server."); } @@ -47,8 +46,7 @@ export const useDeleteRegistration = () => { } else { toast.error("Deletion failed on the server side."); } - } catch (error) { - console.error("Error during deletion:", error); + } catch { toast.error("Unexpected error occurred."); } finally { setAppLoading!(false); diff --git a/frontend/src/hooks/registration-hooks/useGetRegistration.ts b/frontend/src/hooks/registration-hooks/useGetRegistration.ts index 4b763a1..c15bdf8 100644 --- a/frontend/src/hooks/registration-hooks/useGetRegistration.ts +++ b/frontend/src/hooks/registration-hooks/useGetRegistration.ts @@ -32,7 +32,6 @@ const useGetRegistration = () => { const registration = await response.json(); setRegistration(registration); } catch (err) { - console.error("Unexpected error:", err); alert(err); } finally { setLoading(false); diff --git a/frontend/src/hooks/useAddRegistration.ts b/frontend/src/hooks/useAddRegistration.ts index f9b631f..a8e2063 100644 --- a/frontend/src/hooks/useAddRegistration.ts +++ b/frontend/src/hooks/useAddRegistration.ts @@ -26,8 +26,7 @@ export const useAddRegistration = () => { const error: BackendMessage = await response.json(); setError(error); } - } catch (error) { - console.error("Unexpected error:", error); + } catch { setError({ message: "An unexpected error occurred" } as BackendMessage); } finally { setTimeout(() => { diff --git a/frontend/src/hooks/useGetRegistration.ts b/frontend/src/hooks/useGetRegistration.ts index 56da27a..0d0e64a 100644 --- a/frontend/src/hooks/useGetRegistration.ts +++ b/frontend/src/hooks/useGetRegistration.ts @@ -32,7 +32,6 @@ const useGetRegistration = () => { const registration = await response.json(); setRegistration(registration); } catch (err) { - console.error("Unexpected error:", err); alert(err); } finally { setLoading(false); diff --git a/frontend/src/hooks/useUser.ts b/frontend/src/hooks/useUser.ts index e7d33f1..28362da 100644 --- a/frontend/src/hooks/useUser.ts +++ b/frontend/src/hooks/useUser.ts @@ -28,8 +28,7 @@ const useUser = () => { } const user: UserType = await response.json(); setData(user); - } catch (err) { - console.error("Error fetching user:", err); + } catch { setError({ message: "An unexpected error occurred" } as BackendMessage); } finally { setLoading(false); diff --git a/frontend/src/hooks/violation-hooks/useAddViolation.ts b/frontend/src/hooks/violation-hooks/useAddViolation.ts index 75d58a3..88020da 100644 --- a/frontend/src/hooks/violation-hooks/useAddViolation.ts +++ b/frontend/src/hooks/violation-hooks/useAddViolation.ts @@ -24,7 +24,6 @@ const useAddViolation = () => { if (!response.ok) { const errorData = await response.json(); - console.error("Error response from server:", errorData); // Log server response toast.error(errorData.message); return; } diff --git a/frontend/src/hooks/violation-hooks/useDeleteViolation.ts b/frontend/src/hooks/violation-hooks/useDeleteViolation.ts index d1dd85c..cf74f41 100644 --- a/frontend/src/hooks/violation-hooks/useDeleteViolation.ts +++ b/frontend/src/hooks/violation-hooks/useDeleteViolation.ts @@ -22,10 +22,7 @@ export const useDeleteViolation = () => { if (!response.ok) { const errorData = await response.json(); - console.error("Error response from server:", errorData); // Log server response - toast.error(errorData.message); - return; } @@ -34,7 +31,7 @@ export const useDeleteViolation = () => { return; } catch (err: unknown) { - console.error("Network error:", err); + toast.error("Network error occurred."); // Narrow down `err` to ensure it has a `message` property const errorMessage = diff --git a/frontend/src/hooks/violation-hooks/useEditViolation.ts b/frontend/src/hooks/violation-hooks/useEditViolation.ts index c7d8cbf..e966c6b 100644 --- a/frontend/src/hooks/violation-hooks/useEditViolation.ts +++ b/frontend/src/hooks/violation-hooks/useEditViolation.ts @@ -24,11 +24,10 @@ export const useEditViolation = () => { if (!response.ok) { const errorData = await response.json(); - console.error("Error response from server:", errorData); // Log server response toast.error(errorData.message); return; } - + const notificationAPI = await response.json(); toast.success(notificationAPI.message); diff --git a/frontend/src/pages/AddDriver.tsx b/frontend/src/pages/AddDriver.tsx index 07745c4..7d4b384 100644 --- a/frontend/src/pages/AddDriver.tsx +++ b/frontend/src/pages/AddDriver.tsx @@ -66,7 +66,7 @@ const AddDriver = () => { }, 5000); } catch (error) { setLoading(false); - console.error("Error submitting driver:", error); + toast.error((error as Error).message); } }; diff --git a/frontend/src/pages/RegisterDriver.tsx b/frontend/src/pages/RegisterDriver.tsx index 87b995f..6d905fb 100644 --- a/frontend/src/pages/RegisterDriver.tsx +++ b/frontend/src/pages/RegisterDriver.tsx @@ -102,7 +102,7 @@ const RegisterDriver = () => { const isValid = validateForm(); // Validate the form if (isValid) navigate("/homepage"); // Redirect to the homepage } catch (error) { - console.error("Error submitting the form:", error); + toast.error((error as Error).message); } }; const handleChange = (