throwable
throwable is an object that contains methods to check if an error is an internal Brisa trowable. It is used to handle specific scenarios such as re-rendering, navigation, and not-found errors.
- throwable.is: checks all throwable types.
- throwable.isRerender checks if an error is a re-render throwable (from
renderPageandrenderComponentAPI). - throwable.isNavigate checks if an error is a navigate throwable (from
navigateAPI). - throwable.isNotFound checks if an error is a not-found throwable (from
notFoundAPI).
Reference
throwable.is(error: Error): boolean
The throwable.is function checks if a given error is some of the Brisa throwables: re-rendering, navigation, and not-found errors.
Example usage
import {throwable} from "brisa";
// ...
catch (error) {
if (throwable.is(error)) throw error;
}
Parameters:
error: The error object that needs to be checked if it's aThrowable.
Returns:
- A
booleanindicating whether the provided error is an instance of theThrowableclass.
Submethods
throwable.isRerender(error: Error): boolean
Determines if an error is a Throwable instance for re-rendering.
import {throwable} from "brisa";
// ...
catch (error) {
if (throwable.isRerender(error)) {
console.log("It's a rerender throwable!");
}
}
Parameters:
error: The error object that needs to be checked if it's arerenderthrowable.
Returns:
- A
booleanindicating whether the provided error is an instance of thererenderthrowable.
throwable.isNavigate(error: Error): boolean
Determines if an error is a Throwable instance for navigation.
import {throwable} from "brisa";
// ...
catch (error) {
if (throwable.isNavigate(error)) {
console.log("It's a navigate throwable!");
}
}
Parameters:
error: The error object that needs to be checked if it's anavigatethrowable.
Returns:
- A
booleanindicating whether the provided error is an instance of thenavigatethrowable.
throwable.isNotFound(error: Error): boolean
Determines if an error is a Throwable instance for not-found errors.
import {throwable} from "brisa";
// ...
catch (error) {
if (throwable.isNotFound(error)) {
console.log("It's a not-found throwable!");
}
}
Parameters:
error: The error object that needs to be checked if it's anotFoundthrowable.
Returns:
- A
booleanindicating whether the provided error is an instance of thenotFoundthrowable.
Types
interface Throwable {
is: (error: Error) => boolean;
isRerender: (error: Error) => boolean;
isNavigate: (error: Error) => boolean;
isNotFound: (error: Error) => boolean;
}
export const throwable: Throwable;