Reference

Exception

Throwing exceptions will automatically invoke the error page with a matching HTTP status code.

/site/config/config.php
return [
  'routes' => [
    [
      'pattern' => 'custom/response',
      'action'  => function () {
        throw new Exception('Something went horribly wrong');
      }
    ]
  ]
];