From 07814798d13b2fac76ee8535f4e7edf57bc542ed Mon Sep 17 00:00:00 2001 From: Ben Turner Date: Sat, 9 Mar 2024 23:22:37 +0000 Subject: [PATCH] removeprefixes from error messages --- src/routers/qr-code.router.test.ts | 4 +--- src/routers/qr-code.router.ts | 3 +-- src/services/attendance.service.test.ts | 8 +++----- src/services/attendance.service.ts | 6 ++---- src/services/auth.service.test.ts | 4 ++-- src/services/auth.service.ts | 5 ++--- src/services/qr-code.service.ts | 2 +- 7 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/routers/qr-code.router.test.ts b/src/routers/qr-code.router.test.ts index 74f08d7..b6c8d90 100644 --- a/src/routers/qr-code.router.test.ts +++ b/src/routers/qr-code.router.test.ts @@ -82,9 +82,7 @@ describe("qr-code-router.ts", () => { const response = await mockServer().get("/api/qr-code/generate"); expect(response.status).toBe(500); expect(getLocationCoordinatesSpy).toHaveBeenCalledTimes(1); - expect(response.body.message).toEqual( - "InvalidLocation: Invalid location of request", - ); + expect(response.body.message).toEqual("Invalid location of request"); }); }); diff --git a/src/routers/qr-code.router.ts b/src/routers/qr-code.router.ts index 24b6846..36c66ce 100644 --- a/src/routers/qr-code.router.ts +++ b/src/routers/qr-code.router.ts @@ -15,8 +15,7 @@ qrCodeRouter.get("/generate", async (req, res, next) => { const ip = parseIp(req); if (isProductionEnv()) { const coords = await getLocationCoordinates(ip as string); - if (!validateCoords(coords)) - throw Error("InvalidLocation: Invalid location of request"); + if (!validateCoords(coords)) throw Error("Invalid location of request"); } const accessToken = generateAccessToken(); const payload = encodeURI( diff --git a/src/services/attendance.service.test.ts b/src/services/attendance.service.test.ts index ea34a62..f900da6 100644 --- a/src/services/attendance.service.test.ts +++ b/src/services/attendance.service.test.ts @@ -46,10 +46,10 @@ describe("attendance.service.test.ts", () => { } catch (err) { const { message, name } = err as Error; expect(name).toBe("Error"); - expect(message).toBe("InvalidCheckout: No entries found"); + expect(message).toBe("No entries found"); } }); - it("should throw InvalidCheckout error if last entry has an end date", async () => { + it("should throw error if last entry has an end date", async () => { jest.spyOn(EntryModel, "find").mockImplementationOnce( jest.fn().mockReturnValue({ sort: jest.fn().mockResolvedValue([{ end: new Date() }]), @@ -64,9 +64,7 @@ describe("attendance.service.test.ts", () => { } catch (err) { const { message, name } = err as Error; expect(name).toBe("Error"); - expect(message).toContain( - "InvalidCheckout: Latest entry already has checked out at", - ); + expect(message).toContain("Latest entry already has checked out at"); } }); diff --git a/src/services/attendance.service.ts b/src/services/attendance.service.ts index f74b3c7..37e36ed 100644 --- a/src/services/attendance.service.ts +++ b/src/services/attendance.service.ts @@ -17,11 +17,9 @@ export const checkOut = async (payload: EntryPayload) => { createdAt: "desc", }); const latest = entries[0]; - if (!latest) throw Error("InvalidCheckout: No entries found"); + if (!latest) throw Error("No entries found"); if (latest.end) - throw Error( - "InvalidCheckout: Latest entry already has checked out at " + latest.end, - ); + throw Error("Latest entry already has checked out at " + latest.end); latest.end = new Date(); return await latest.save(); }; diff --git a/src/services/auth.service.test.ts b/src/services/auth.service.test.ts index fe8d9fb..9845066 100644 --- a/src/services/auth.service.test.ts +++ b/src/services/auth.service.test.ts @@ -20,7 +20,7 @@ describe("auth.service.ts", () => { }); expect(success).toBe(false); } catch (err) { - expect((err as Error).message).toBe("Unauthorized: No user found"); + expect((err as Error).message).toBe("No user found"); } }); @@ -45,7 +45,7 @@ describe("auth.service.ts", () => { }); expect(success).toBe(false); } catch (err) { - expect((err as Error).message).toBe("Unauthorized: Invalid password"); + expect((err as Error).message).toBe("Invalid password"); expect(mockUpdate).toHaveBeenCalledWith("invalid-password", "utf8"); } }); diff --git a/src/services/auth.service.ts b/src/services/auth.service.ts index 032dc9b..85ccddd 100644 --- a/src/services/auth.service.ts +++ b/src/services/auth.service.ts @@ -24,11 +24,10 @@ export const generateAdminAccessToken = () => { export const validateAdminPassword = async (payload: AdminLoginPayload) => { const adminUser = await UserModel.findOne({ username: payload.username }); - if (!adminUser) throw Error("Unauthorized: No user found"); + if (!adminUser) throw Error("No user found"); const hash = createHash("sha256") .update(payload.password, "utf8") .digest("hex"); - if (hash !== adminUser.password) - throw Error("Unauthorized: Invalid password"); + if (hash !== adminUser.password) throw Error("Invalid password"); return { success: true }; }; diff --git a/src/services/qr-code.service.ts b/src/services/qr-code.service.ts index 1d4ed68..59a3ec9 100644 --- a/src/services/qr-code.service.ts +++ b/src/services/qr-code.service.ts @@ -23,7 +23,7 @@ export const decodeQRCodeDataUrl = async ( return decoded.data; } catch (err) { - console.error(Error("Error: QR Decoding failed")); + console.error(Error("QR Decoding failed")); console.error(err); } };