Why error.code returns undefined
Unanswered
Scaly-naped Pigeon posted this in #help-forum
Scaly-naped PigeonOP
class CustomError extends Error {
code: number = 0;
constructor(message: string, code: number) {
super(message);
this.code = code;
}
}export async function checkError(res: Response) {
if (res.ok) return;
throw new CustomError("test", res.status);
}export default function Error({
error,
reset
}: {
error: CustomError & { digest?: string };
reset: () => void;
}) {
useEffect(() => {
console.log(error.code);
}, [error]);
return (
<div>
<h2>{error.message}</h2>
<button onClick={() => reset()}>Try again</button>
</div>
);
}error.code returns undefined in Erorr.
What is the reason?
res.status in checkError returns 401