From 5b875f37494678fe08dea4157507027527e9aa61 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 21 Sep 2016 15:58:59 +0200 Subject: [PATCH] JsonResponse: Allow to output the "data" key in case of an error As stated by the JSend specification this key is optional for error responses. --- library/Icinga/Web/Response/JsonResponse.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/library/Icinga/Web/Response/JsonResponse.php b/library/Icinga/Web/Response/JsonResponse.php index 9f2cd95cf..8a9ba7d33 100644 --- a/library/Icinga/Web/Response/JsonResponse.php +++ b/library/Icinga/Web/Response/JsonResponse.php @@ -121,7 +121,7 @@ class JsonResponse extends Response */ public function getFailData() { - return $this->failData; + return (! is_array($this->failData) || empty($this->failData)) ? null : $this->failData; } /** @@ -173,9 +173,11 @@ class JsonResponse extends Response switch ($this->status) { case static::STATUS_ERROR: $body['message'] = $this->getErrorMessage(); - break; case static::STATUS_FAIL: - $body['data'] = $this->getFailData(); + $failData = $this->getFailData(); + if ($failData !== null || $this->status === static::STATUS_FAIL) { + $body['data'] = $failData; + } break; case static::STATUS_SUCCESS: $body['data'] = $this->getSuccessData();