setStatusCode(500); $data = $response->getData(true); if ($this->debug) { $data = array_merge($data, [ 'code' => $e->getCode(), 'message' => $e->getMessage(), 'exception' => (string)$e, 'line' => $e->getLine(), 'file' => $e->getFile() ]); } else { $data['message'] = $e->getMessage(); } $response->setData($data); } }