ServerParseError
API reference
Represents a failure to parse the response as JSON from the server. This error helps debug issues where the server returns malformed JSON or non-JSON content.
This error occurs when Apollo Client receives a response from the server but cannot parse it as valid JSON. This typically happens when the server returns HTML error pages, plain text responses, or malformed JSON instead of the expected GraphQL JSON response format.
1 import { ServerParseError } from "@apollo/client/errors"; 2 3 // Check if an error is a ServerParseError instance 4 if (ServerParseError.is(error)) { 5 console.log(`Failed to parse response from ${error.response.url}`); 6 console.log(`Raw response: ${error.bodyText}`); 7 console.log(`Status code: ${error.statusCode}`); 8 9 // Access the original parse error 10 console.log(`Parse error: ${error.cause}`); 11 }
Static methods
A method that determines whether an error is a ServerParseError
object. This method enables TypeScript to narrow the error type.
Example
1 if (ServerParseError.is(error)) { 2 // TypeScript now knows `error` is a ServerParseError object 3 console.log(error.statusCode); 4 }
Signature
1is( 2 error: unknown 3): error is ServerParseError
See the instance properties for more details about the available properties provided by the ServerParseError
object.
Instance properties
These properties are specific to the ServerParseError
object. Standard error instance properties are also available.
cause
property to access the original parse error thrown by JSON.parse()
.string
The raw response body text.
Response
number
The status code returned by the server in the response. This is provided as a shortcut for response.status
.