/** * Takes an Error Exception and gets the available error information * and creates a body of it and returns the body. * * @param Exception $exception * @return array */ private function prepareErrorBody(Exception $exception) { // Prepare body $body = ['errors' => []]; // Set HTTP status code if (!empty($statusCode = $exception->getStatusCode())) { $body['errors']['statusCode'] = $statusCode; } // Check if a description exists if (!empty($description = $exception->getDescription())) { $body['errors']['description'] = $description; } // Check if a message has been defined if (!empty($message = $exception->getMessage())) { $body['errors']['message'] = $message; } // Check if an error code has been defined if (!empty($code = $exception->getCode())) { $body['errors']['code'] = $code; } // Check if a link has been specified if (!empty($link = $exception->getLink())) { $body['errors']['link'] = $link; } return $body; }