From a4b5b9018b0fd29ddd2da05f8a41be5eaebd0479 Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 26 Nov 2024 18:27:55 -0500 Subject: [PATCH] updated type guard for custom error class --- app/dashboard/debug/displayForm.tsx | 13 +------------ errors/typeGuards.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/dashboard/debug/displayForm.tsx b/app/dashboard/debug/displayForm.tsx index 97e3e3f..7641b85 100644 --- a/app/dashboard/debug/displayForm.tsx +++ b/app/dashboard/debug/displayForm.tsx @@ -10,7 +10,7 @@ import { } from "@/types/types"; import { toast } from "sonner"; -import { isPlainAppError, PlainAppError } from "@/errors"; +import { AppError, isPlainAppError, PlainAppError } from "@/errors"; import { addCategory, addTransaction, deleteCategory, updateCategoryName, updateMonthlyGoal } from "@/actions"; import { Button } from "@/components/button"; import { RadioField, RadioGroup } from "@/components/radio"; @@ -413,17 +413,6 @@ export default function DisplayForm({ {loading &&
Loading...
} - {/*
- {Array.isArray(categoryWithDetails) && - categoryWithDetails.map((c) => ( -
-
{JSON.stringify(c, null, 2)}
- {!isPlainAppError(monthlyBudget) && ( -

Monthly budget id: {monthlyBudget.id}

- )} -
- ))} -
*/} ); } diff --git a/errors/typeGuards.ts b/errors/typeGuards.ts index b10a333..c51a383 100644 --- a/errors/typeGuards.ts +++ b/errors/typeGuards.ts @@ -7,8 +7,16 @@ export function isPlainAppError(obj: any): obj is PlainAppError { "error" in obj && typeof obj.error === "object" && "name" in obj.error && + typeof obj.error.name === "string" && "message" in obj.error && + typeof obj.error.message === "string" && "code" in obj.error && - "status" in obj.error + typeof obj.error.code === "string" && + "status" in obj.error && + typeof obj.error.status === "number" && + "details" in obj.error && + typeof obj.error.details === "string" && + "hint" in obj.error && + typeof obj.error.hint === "object" ); }