Something went wrong. Try again.
because I got bored of customising my CV for every job
Something went wrong. Try again.
1.3 kB · 47 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import { GraphQLErrorWrapperSchema } from "./graphql-error.schema";
export const extractGraphQLErrorMessage = (error: unknown): string => { const validationResult = GraphQLErrorWrapperSchema.safeParse(error);
if (!validationResult.success) { return "An unexpected error occurred"; }
const { response, message } = validationResult.data;
if (response?.errors?.[0]?.message) { return response.errors[0].message; }
if (message) { return message; }
return "An unexpected error occurred";};
export const extractGraphQLErrorCode = (error: unknown): string | null => { const validationResult = GraphQLErrorWrapperSchema.safeParse(error);
if (!validationResult.success) { return null; }
const firstError = validationResult.data.response?.errors?.[0]; return ( (firstError?.extensions as { code?: string } | undefined)?.code ?? null );};
export const extractGraphQLErrorVariables = ( error: unknown,): Record<string, string | number | string[] | number[]> | null => { const validationResult = GraphQLErrorWrapperSchema.safeParse(error);
if (!validationResult.success) { return null; }
const firstError = validationResult.data.response?.errors?.[0]; return firstError?.extensions?.variables ?? null;};