Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

feat(api): allow content return on rest exceptions #5795

Merged
merged 1 commit into from
Nov 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions www/class/centreonRestHttp.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ private function insertLog($output, $url, $type = 'RestInternalServerErrorExcept
* @param string $method The HTTP method
* @param array|null $data The data to send on the request
* @param array $headers The extra headers without Content-Type
* @param bool $throwContent
* @return array The result content
*/
public function call($url, $method = 'GET', $data = null, $headers = array())
public function call($url, $method = 'GET', $data = null, $headers = array(), $throwContent = false)
{
/* Add content type to headers */
$headers[] = 'Content-type: ' . $this->contentType;
Expand Down Expand Up @@ -167,7 +168,13 @@ public function call($url, $method = 'GET', $data = null, $headers = array())
}

if (!is_null($exceptionClass)) {
$message = isset($decodedContent['message']) ? $decodedContent['message'] : $logMessage;
if ($throwContent && is_array($decodedContent)) {
$message = json_encode($decodedContent);
} elseif (isset($decodedContent['message'])) {
$message = $decodedContent['message'];
} else {
$message = $logMessage;
}
$this->insertLog($message, $url, $exceptionClass);
throw new $exceptionClass($message);
}
Expand Down