protected function defaultError($e) { $mediaType = $this->request->getMediaType(); // Standard exception data $error = array('code' => $e->getCode(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()); if (is_subclass_of($e, 'api\\Exception') && $this->getMode() == 'production') { $error['message'] = 'There was an internal error'; unset($error['file'], $error['line']); } // Custom error data (e.g. Validations) if (method_exists($e, 'getData')) { $errors = $e->getData(); } if (!empty($errors)) { $error['errors'] = $errors; } $this->getLog()->error($e->getMessage()); if ('application/json' === $mediaType || true === $this->isAPI()) { $this->response->headers->set('Content-Type', 'application/json'); echo json_encode($error, JSON_PRETTY_PRINT); } else { parent::defaultError($e); } }