Error Handling
There are 2 ways you can handle errors in GraphQL: you can either have documents throw an exception if an
error key is located in the payload (and is a list with at least one member) or they can fail silently
and rely on application level code to function.
By default, Houdini will behave “silently” and not throw any exceptions if an error is the query response is
seen. If you want to turn on exceptions, you can specify the details in the throwOnError field:
export default new HoudiniClient({ url: '...', throwOnError: { // can be any combination of // query, mutation, subscription, and all operations: ['all'], // the function to call error: (errors, ctx) => new Error( `(${ctx.artifact.name}): ` + errors.map((err) => err.message).join('. ') + '.' ) }})export default new HoudiniClient({ url: '...', throwOnError: { // can be any combination of // query, mutation, subscription, and all operations: ['all'], // the function to call error: (errors, ctx) => new Error(`(${ctx.artifact.name}): ` + errors.map((err) => err.message).join('. ') + '.') }})Mutation functions will throw if the server response contains an error. The resulting exception will have the message
field of every error joined with a period. If you want access to the full error payload, you can access the raw field:
import { type RuntimeGraphQLError } from '$houdini'
try { await mutate()} catch (e) { const err = e as RuntimeGraphQLError console.log(err.raw)}