Micro app, handle 500 errors

Hi! I have an issue with micro app. My app is very simple:

index.php

define('BASE_PATH', dirname(__DIR__));
define('APP_PATH', BASE_PATH . '/app');

$loader = new \Phalcon\Loader();
$loader->registerDirs([
    APP_PATH . '/classes'
]);
$loader->register();

$app = new \Phalcon\Mvc\Micro();

$app->notFound(function() use ($app) {
    $app->response->setStatusCode(404, 'Not Found')->send();
});

$app->error(function($e) {
    echo 'error';
    return false;
});

$col = new \Phalcon\Mvc\Micro\Collection();
$col->setHandler('IndexClass', true);
$col->get('/', 'index');
$app->mount($col);

$app->handle();

IndexClass.php

class IndexClass
{
    public function index() {
        die('index');
    }
}

The problem is the following: when I open home page, I see text 'index' as it's expected. But when I open something like '/lalala' (that is not described in routes) I see 500 error. I'd like to handle it and show 404 page instead. My error handler is not working in this case. What am I missing? Thank you.

Hi @hailie-rei do you have correctly configurated your apache/nginx to redirect all request to index.php?

Hi @emiliodeg, thank you for your attention and answer. I followed the tutorial for micro app to create mine, and I created .htaccess for apache using the code from the tutorial. Today I decided to create a micro app using phalcon-devtools (last version), then I made necessary fixes according to my needs and the problem dissappeared. I didn't research the problem with my first code version, maybe it was because of missing services or something else.

Hi @hailie-rei do you have correctly configurated your apache/nginx to redirect all request to index.php?