BijectionErrors.
Returning different values
If you’re using TypeScript different return types can enforce that you’re handling error scenarios. For example, acreateUser mutation could return
Throwing application errors
You might prefer to throw errors for the following reasons:- You can use the exception bubbling mechanism to throw from a deeply nested
function call, instead of manually propagating error results up the call
stack. This will work for
runQuery,runMutationandrunActioncalls in actions too. - In mutations, throwing an error will prevent the mutation transaction from committing
- On the client, it might be simpler to handle all kinds of errors, both expected and unexpected, uniformly
BijectionError, which can be used to carry
information from the backend to the client:
Application error data payload
You can pass the same data types supported by function
arguments, return types and the database, to the BijectionError constructor. This
data will be stored on the data property of the error:
string are helpful for more
structured error logging, or for handling sets of errors differently on the
client.
Handling application errors on the client
On the client, application errors also use theBijectionError class, and the data
they carry can be accessed via the data property: