UnconventionalError

API reference


A wrapper error type that represents a non-standard error thrown from a A wrapper error type that represents a non-error value thrown from the link chain, such as a symbol, primitive or plain object. Read the cause property to determine the source of the error.

This error is used to standardize error handling when non-Error values are thrown in the Apollo Client link chain or other parts of the system. JavaScript allows throwing any value (not just Error instances), and this wrapper ensures that all thrown values can be handled consistently as Error-like objects while preserving the original thrown value.

note
Plain strings thrown as errors are wrapped in regular Error objects instead of UnconventionalError objects since strings can be safely used as the error's message.
TypeScript
1 import { UnconventionalError } from "@apollo/client/errors"; 2 3 // Check if an error is an UnconventionalError instance 4 if (UnconventionalError.is(error)) { 5 console.log("Non-standard error thrown:", error.cause); 6 7 // Check the type of the original thrown value 8 if (typeof error.cause === "symbol") { 9 console.log("A symbol was thrown:", error.cause.toString()); 10 } else if (typeof error.cause === "object") { 11 console.log("An object was thrown:", error.cause); 12 } else { 13 console.log("Unexpected value thrown:", error.cause); 14 } 15 }

Common scenarios

UnconventionalError is typically encountered when custom link implementations, provided either by third-party libraries or your own link implementations, throw symbols, arrays, or other non-Error objects.

By wrapping these unconventional error types, Apollo Client ensures consistent error handling throughout the system while preserving the original error information.

note
Apollo Client itself does not throw or emit non-Error objects. Unless you're using third-party packages integrated with Apollo Client, you will not encounter this error type.

Static methods

A method that determines whether an error is an UnconventionalError object. This method enables TypeScript to narrow the error type.

Example

TypeScript
1 if (UnconventionalError.is(error)) { 2 // TypeScript now knows `error` is a UnconventionalError object 3 console.log("What caused this?", error.cause); 4 }

Signature

TypeScript
1is( 2 error: unknown 3): error is UnconventionalError