{"record":{"id":"49febcac7c65bfa2","repo":"marmelab/react-admin","slug":"error-networkerror-as-servererror-message","errorCode":null,"errorMessage":"${(error?.networkError as ServerError)?.message}","messagePattern":"\\$\\{\\(error\\?\\.networkError as ServerError\\)\\?\\.message\\}","errorType":"http","errorClass":"HttpError","httpStatus":null,"severity":"error","filePath":"packages/ra-data-graphql/src/index.ts","lineNumber":259,"sourceCode":"                if (!introspectionResultsPromise) {\n                    introspectionResultsPromise = resolveIntrospection(\n                        client,\n                        introspection\n                    );\n                }\n\n                return introspectionResultsPromise;\n            }\n        },\n        client,\n    };\n\n    return raDataProvider;\n};\n\nconst handleError = (error: ApolloError) => {\n    if (error?.networkError as ServerError) {\n        throw new HttpError(\n            (error?.networkError as ServerError)?.message,\n            (error?.networkError as ServerError)?.statusCode\n        );\n    }\n\n    throw new HttpError(error.message, 200, error);\n};\n\nconst getQueryOperation = query => {\n    if (query && query.definitions && query.definitions.length > 0) {\n        return query.definitions[0].operation;\n    }\n\n    throw new Error('Unable to determine the query operation');\n};\n\nexport type GetIntrospection = () => Promise<IntrospectionResult>;\nexport type GraphqlDataProvider = DataProvider & {","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-data-graphql/src/index.ts#L241-L277","documentation":"handleError converts ApolloError instances into react-admin HttpErrors. When the error carries a networkError typed as ServerError, its message and statusCode are used; this surfaces network-level failures (non-2xx responses from the GraphQL endpoint) as the thrown error message.","triggerScenarios":"Any Apollo client request that fails at the network/HTTP level — server returning 4xx/5xx, gateway errors, server down — so ApolloError.networkError is a ServerError whose message becomes the thrown HttpError message.","commonSituations":"GraphQL server returning 500 with an HTML error page; auth middleware returning 401/403; wrong apiUrl; reverse proxy errors; server crashes.","solutions":["Inspect the networkError's message/statusCode to identify the underlying HTTP failure.","Fix the server-side error indicated by the status code (500 = server bug, 401 = auth, 404 = wrong URL).","Verify the GraphQL endpoint URL and that the server is reachable (test with curl/Postman).","Check server logs or proxy logs for the actual failure."],"exampleFix":"// before\nconst client = new ApolloClient({ uri: 'https://api.example.com/gql' }); // 404\n// after\nconst client = new ApolloClient({ uri: 'https://api.example.com/graphql' });","handlingStrategy":"try-catch","validationCode":"// Preflight the endpoint before app use:\nconst res = await fetch(graphqlUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{\"query\":\"{ __typename }\"}' });\nif (!res.ok) throw new Error(`GraphQL endpoint unhealthy: ${res.status}`);","typeGuard":"const isServerError = (e: unknown): e is { message: string; statusCode: number } =>\n  typeof e === 'object' && e !== null && 'statusCode' in e && typeof (e as any).statusCode === 'number';","tryCatchPattern":"try {\n  return await dataProvider.getList(resource, params);\n} catch (e) {\n  if (e instanceof HttpError && e.body instanceof ApolloError && e.body.networkError) {\n    const se = e.body.networkError as ServerError;\n    console.error(`GraphQL network failure ${se.statusCode}: ${se.message}`);\n  }\n  throw e;\n}","preventionTips":["Monitor the GraphQL endpoint's health and status codes.","Centralize error handling (e.g. a query error callback) to log networkError details.","Check server/proxy logs when 5xx statuses appear.","Validate apiUrl configuration per environment."],"tags":["graphql","network","apollo","http-error"],"backgroundTag":"http-server-error","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}