because I got bored of customising my CV for every job
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 47 lines 1.3 kB view raw
1import { GraphQLErrorWrapperSchema } from "./graphql-error.schema"; 2 3export const extractGraphQLErrorMessage = (error: unknown): string => { 4 const validationResult = GraphQLErrorWrapperSchema.safeParse(error); 5 6 if (!validationResult.success) { 7 return "An unexpected error occurred"; 8 } 9 10 const { response, message } = validationResult.data; 11 12 if (response?.errors?.[0]?.message) { 13 return response.errors[0].message; 14 } 15 16 if (message) { 17 return message; 18 } 19 20 return "An unexpected error occurred"; 21}; 22 23export const extractGraphQLErrorCode = (error: unknown): string | null => { 24 const validationResult = GraphQLErrorWrapperSchema.safeParse(error); 25 26 if (!validationResult.success) { 27 return null; 28 } 29 30 const firstError = validationResult.data.response?.errors?.[0]; 31 return ( 32 (firstError?.extensions as { code?: string } | undefined)?.code ?? null 33 ); 34}; 35 36export const extractGraphQLErrorVariables = ( 37 error: unknown, 38): Record<string, string | number | string[] | number[]> | null => { 39 const validationResult = GraphQLErrorWrapperSchema.safeParse(error); 40 41 if (!validationResult.success) { 42 return null; 43 } 44 45 const firstError = validationResult.data.response?.errors?.[0]; 46 return firstError?.extensions?.variables ?? null; 47};