This page is about handling bugs and network errors.
- To block unauthorized access: Guides > Permissions
- To handle invalid
<form>
values: Guides > Form validation- To install error tracking: API >
onBug()
If a telefunction has a bug:
// hello.telefunc.js
// Environment: Node.js
export { hello }
function hello(name) {
// This telefunction has a bug: it should be `name` instead of `namee`
return 'Hello ' + namee
}
Then telefunction calls throw an error:
<!-- index.html -->
<!-- Environment: Browser -->
<html>
<body>
<script type="module">
import { hello } from './hello.telefunc.js'
try {
await hello('Eva')
console.log("I'm never printed")
} catch(err) {
console.log(err.message) // Prints 'Internal Server Error'
}
</script>
</body>
</html>
To avoid leaking sensitive information, Telefunc doesn't send the original Error
to the frontend.
For expected errors, such as authentication and validation errors, we can propagate error information to the frontend by using
throw Abort(someValue)
, see for example Guides > Permissions >getContext()
wrapping.
If the user's browser can't connect to our server:
<!-- index.html -->
<!-- Environment: Browser -->
<html>
<body>
<script type="module">
import { hello } from './hello.telefunc.js'
try {
await hello('Eva')
} catch(err) {
if (err.isConnectionError) {
// There is a network problem:
// - the user isn't connected to the internet, or
// - our server is down.
console.log(err.message) // Prints 'No Server Connection'
}
}
</script>
</body>
</html>