Skip to content

Error Handling

The client package provides two error classes that distinguish between GraphQL-level errors and network-level failures.

Thrown when the GraphQL server returns a response with an errors array. The HTTP status may still be 200 (the standard for GraphQL error responses).

PropertyTypeDescription
messagestringAll error messages joined with '; '
errorsGraphQLErrorEntry[]The full array of error entries from the response
statusnumberHTTP status code (typically 200)

Each GraphQLErrorEntry has:

type GraphQLErrorEntry = {
message: string
locations?: { line: number; column: number }[]
path?: (string | number)[]
extensions?: Record<string, unknown>
}

Thrown when the HTTP request fails entirely (network unreachable, DNS failure, non-OK HTTP status).

PropertyTypeDescription
messagestringError description (e.g., 'HTTP 500: Internal Server Error')
statusnumberHTTP status code, or 0 if the request never completed
import { GraphQLClientError, NetworkError } from '@graphql-suite/client'
try {
const articles = await client.entity('article').query({
select: { id: true, title: true },
})
} catch (e) {
if (e instanceof GraphQLClientError) {
// Server returned GraphQL errors
console.error('GraphQL errors:', e.errors)
console.error('Status:', e.status)
} else if (e instanceof NetworkError) {
// Request failed at the network level
console.error('Network error:', e.message)
console.error('Status:', e.status)
}
}
ScenarioError classstatus
Network unreachable / DNS failureNetworkError0
HTTP 4xx or 5xx responseNetworkErrorHTTP status code
HTTP 200 with errors in JSON bodyGraphQLClientError200
HTTP 200 with no data in JSON bodyGraphQLClientError200