# \[SOLVED\] Return response from custom ErrorController without template

**URL:** <https://discourse.cakephp.org/t/solved-return-response-from-custom-errorcontroller-without-template/10630>\
**Category:** Uncategorized\
**Created:** [September 14, 2022, 5:41pm UTC](https://discourse.cakephp.org/t/solved-return-response-from-custom-errorcontroller-without-template/10630 "2022-09-14T17:41:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mvojwe](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@mvojwe](https://discourse.cakephp.org/u/mvojwe)\
**Post date:** [September 14, 2022, 5:41pm UTC](https://discourse.cakephp.org/t/solved-return-response-from-custom-errorcontroller-without-template/10630/1 "2022-09-14T17:41:42Z")

</div>

I’m trying to catch all the Exceptions on my prefix /api/v1.  
I’ve read the [book](https://book.cakephp.org/4/en/development/errors.html#custom-errorcontroller) and made this:

config/routes.php  
 ![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/9/979fc8119def620eb0536e15fd09112de6254ccc.png)

src/Controller/Api/V1/ErrorController.php  
 ![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/c/c3efcec6a3ba5041a28302b4e7c8d85affdb0d38.png)

My problem is that if I throw an Exception, the controller displays the template in templates/Error/error500.php even if I use $event-\>stopPropagation().

Instead, I need to return just the number “1”.  
I’ve found a messy workaround which is calling echo “1” and die, but I dont want to do this because I’ve found a content length bigger than 1 on the response header in some servers.

What am I doing wrong? Thanks in advance!

**[SOLVED] Finally fixed it with this code…**

```auto
<?php

declare(strict_types=1);

namespace App\Controller\Api\V1;

use Cake\Controller\Controller;
use Cake\Event\EventInterface;

class ErrorController extends Controller
{
    public function beforeRender(EventInterface $event)
    {
        $event->stopPropagation();

        $this->response = $this->response
            ->withHeader('Connection', 'close')
            ->withLength(1)
            ->withType('text/html')
            ->withStringBody('0');
    }
}

```
