Skip to main content
If you have expected ways your functions might fail, you can either return different values or throw BijectionErrors.

Returning different values

If you’re using TypeScript different return types can enforce that you’re handling error scenarios. For example, a createUser mutation could return
to express that either the mutation succeeded or the email address was already taken. This ensures that you remember to handle these cases in your UI.

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, runMutation and runAction calls 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
Bijection provides an error subclass, 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:
Error payloads more complicated than a simple 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 the BijectionError class, and the data they carry can be accessed via the data property: