Skip to content

Commit 43703ee

Browse files
committed
feat: enhance error handling in layout with GraphQLFormattedError support
1 parent 08f577d commit 43703ee

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/app/layout.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {Toaster} from "sonner";
1919
import {Error} from "@code0-tech/sagittarius-graphql-types";
2020
import {toast} from "@code0-tech/pictor";
2121
import {Inter} from 'next/font/google'
22+
import {GraphQLFormattedError} from "graphql/error";
2223

2324
/**
2425
* Load the Inter font with Latin subset and swap display strategy
@@ -66,8 +67,8 @@ const ErrorCodeDescription: Record<string, string> = {
6667
/**
6768
* Handles error toasts based on error type
6869
*/
69-
const toastHandler = (error: Error) => {
70-
if (error.__typename === "ErrorCode") {
70+
const toastHandler = (error: Error | GraphQLFormattedError) => {
71+
if (error && "errorCode" in error) {
7172
toast({
7273
title: ErrorCodeDescription[(error.errorCode as string)],
7374
color: "error",
@@ -94,7 +95,7 @@ export default function RootLayout({children}: Readonly<{ children: React.ReactN
9495
*/
9596
const errorLink = new ErrorLink(({error, result, operation, forward}) => {
9697
if (error instanceof CombinedGraphQLErrors) {
97-
error.errors.forEach((error: Error) => {
98+
error.errors.forEach((error: GraphQLFormattedError) => {
9899
toastHandler(error)
99100
})
100101
return

0 commit comments

Comments
 (0)