Error handling
This page is about handling bugs, expected errors, and network errors.
- To block unauthorized access: Guides > Permissions
- To handle invalid
<form>
values: Guides > Form validation- To install error tracking: API >
onBug()
Bugs
If a telefunction has a bug:
Then a telefunction call throws an error:
To avoid leaking sensitive information, Telefunc doesn't send the original
Error
object to the frontend.
Expected Errors
An error thrown by a telefunction may not be a bug but an expected error instead.
For example:
- Some authentication libraries throw an error if the user isn't logged in.
- Some validation libraries throw errors upon invalid data.
We can:
- Propagate the error to the frontend, or
- handle the error on the server-side.
1. Propagate the error to the frontend.
We can propagate error information to the frontend like this:
We can also use throw Abort(someValue)
:
In general, we recommend using return { someValue }
instead of throw Abort(someValue)
, see explanation at Guides > Form validation > throw Abort(someValue)
.
We need to catch the error and use
throw Abort(someValue)
because Telefunc doesn't send the originalError
object to the frontend (in order to avoid leaking sensitive information).
Also see Guides > Permissions > getContext()
wrapping.
2. Handle the error on the server-side.
We can handle the thrown error at our Telefunc server middleware:
Also see API > getContext()
> Provide.
Network Errors
If the user's browser can't connect to our server: