Luminova Framework

View Error Controller

Last updated: 2024-05-14 00:26:07

The ViewErrors class allows you define and manage error-handling methods to customize how view errors are displayed. Error-handling methods for 404 error type that may occur during the execution of your application web or api views, provide a way to display meaningful error messages to users.


  • Error handler methods can be either static or non-static.
  • Methods must be declared as public, not protected or private.
  • Dependency injection is enabled by default for error handlers, allowing you to pass any class you need as a parameter in the method signature.
  • After adding a new method for a context error handler or modifying a method name, you must update the corresponding name in the context method located in the /public/index.php file.



The default error handler for the web routing context.

public static onWebError(Application $app): void


$app\App\Controllers\ApplicationApplication instance available


The default error handler for the API routing context.

public static onApiError(Application $app): void


$app\App\Controllers\ApplicationApplication instance available

Usage Example

To register your error handler, it must be callable or pass an array where the first element of the array is your error handler class name and the second element is the method name.

// public/index.php
use \Luminova\Routing\Context;
use App\Controllers\Errors\ViewErrors;

    new Context(Context::FOO, [ViewErrors::class, 'onFooError']),

This example demonstrates how to register an error handler in your application's routing context. The onFooError method from the ViewErrors class will handle errors for the FOO context.