private function handleError($error, Http\Request $request, Http\Response $response)
    {
        $response = $response->withStatus(
            $this->getStatusCode($error, $response)
        );

        $message = $response->getReasonPhrase() ?: 'Unknown Error';
        if (! isset($this->options['env'])
            || $this->options['env'] !== 'production'
        ) {
            $message = $this->createDevelopmentErrorMessage($error);
        }

        $response = $response->end($message);

        $this->triggerError($error, $request, $response);

        return $response;
    }