# Combine Error and ShutdownHandler responses

**URL:** <https://discourse.slimframework.com/t/combine-error-and-shutdownhandler-responses/4526>\
**Category:** Questions\
**Created:** [November 28, 2020, 8:45am UTC](https://discourse.slimframework.com/t/combine-error-and-shutdownhandler-responses/4526 "2020-11-28T08:45:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rcls](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@Rcls](https://discourse.slimframework.com/u/Rcls)\
**Post date:** [November 28, 2020, 8:45am UTC](https://discourse.slimframework.com/t/combine-error-and-shutdownhandler-responses/4526/1 "2020-11-28T08:45:56Z")

</div>

I have a curious problem where **Slim Framework v4** triggers the error handler twice. Once for an exception, once for a PHP `undefined index` error. I can and will fix the index error, but in development this results in invalid JSON response.

The project is set up using the [Skeleton project](https://github.com/slimphp/Slim-Skeleton) and the error handler is the original one found in the repo.

Here is the response:

```json
{
    "statusCode": 500,
    "error": {
        "type": "SERVER_ERROR",
        "description": "Missing foo"
    }
}{
    "statusCode": 500,
    "error": {
        "type": "SERVER_ERROR",
        "description": "ERROR: Undefined index: foo on line 289 in file /var/www/src/Modules/Internal/Controllers/InternalController.php."
    }
}

```

The example response below is from a catched exception, which gets returned as a 401 response:

```json
    {
        "error": "Missing parameter foo"
    }{
        "statusCode": 500,
        "error": {
            "type": "SERVER_ERROR",
            "description": "ERROR: Undefined index: foo on line 291 in file /var/www/src/Modules/Internal/Controllers/InternalController.php."
        }
    }

```

The errors can be triggered by a line like this, which is of course an `Undefined index` error:

```
if (!isset($body['foo']) && !is_string($body['foo']))

```

The fix would be to change AND to OR:

```
if (!isset($body['foo']) || !is_string($body['foo']))

```

My question is how can I get access to an existing response in the `HttpErrorHandler`, to pool these responses to an array, like this:

```json
{
    "errors": [
        { "error": "Missing parameter foo" },
        { "statusCode": 500... }
    }
}

```

I’ve tried digging through the Request object and anything I can, but I’d like a tip.
