Skip to content

Router Configuration

To enable this behavior, you need to configure your Laravel application in app/bootstrap:

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware): void {
$middleware->append(AventusMiddleware::class);
// Transforms responses to JSON with $type for Aventus
})
->withExceptions(function (Exceptions $exceptions): void {
AventusExceptionCatcher::use($exceptions);
// Catches errors and transforms them into AventusResult format
})->create();
  • AventusMiddleware inspects the response type and, when appropriate, transforms it into a JSON object containing the $type property so AventusJs can process it seamlessly.
  • AventusExceptionCatcher ensures that all exceptions are caught and wrapped into the unified AventusResult format, making error handling on the frontend consistent and predictable.

When a error is catched by AventusExceptionCatcher, the error will be printed inside the console by default. To disable this behaviour, you can edit the configuration file laraventus.php. To avoid infinite stack printing, the configuration file contains a parameter stack_limit. To print all the stacks set this parameter to -1

<?php
return [
"error" => [
"print_console" => false,
"stack_limit" => 10
]
];