Skip to content

Commit

Permalink
updated type guard for custom error class
Browse files Browse the repository at this point in the history
  • Loading branch information
vim-diesel committed Nov 26, 2024
1 parent 21105a7 commit a4b5b90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
13 changes: 1 addition & 12 deletions app/dashboard/debug/displayForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -413,17 +413,6 @@ export default function DisplayForm({
</section>
{loading && <div>Loading...</div>}
<Divider className="my-6" />
{/* <section className="mb-8">
{Array.isArray(categoryWithDetails) &&
categoryWithDetails.map((c) => (
<div key={c.id}>
<pre >{JSON.stringify(c, null, 2)}</pre>
{!isPlainAppError(monthlyBudget) && (
<p>Monthly budget id: {monthlyBudget.id}</p>
)}
</div>
))}
</section> */}
</div>
);
}
10 changes: 9 additions & 1 deletion errors/typeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}

0 comments on commit a4b5b90

Please sign in to comment.