From 01d7776fc1a1469ea45bf4a1c2a81032cbf3bfe1 Mon Sep 17 00:00:00 2001 From: nmonterroso Date: Mon, 22 Jun 2015 11:47:23 -0700 Subject: [PATCH] don't create a new response object, and keep the old string value in the exception and have the object as ApiException->responseObject --- .../main/resources/php/ApiException.mustache | 28 +++++++++++++++---- .../src/main/resources/php/api.mustache | 6 ++-- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/ApiException.mustache b/modules/swagger-codegen/src/main/resources/php/ApiException.mustache index 096979c11cb..4b8d205690c 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiException.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiException.mustache @@ -24,17 +24,22 @@ class ApiException extends Exception { /** * The HTTP body of the server response. */ - protected $response_body; + protected $responseBody; /** * The HTTP header of the server response. */ - protected $response_headers; + protected $responseHeaders; + + /** + * The deserialized response object + */ + protected $responseObject; public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) { parent::__construct($message, $code); - $this->response_headers = $responseHeaders; - $this->response_body = $responseBody; + $this->responseHeaders = $responseHeaders; + $this->responseBody = $responseBody; } /** @@ -43,7 +48,7 @@ class ApiException extends Exception { * @return string HTTP response header */ public function getResponseHeaders() { - return $this->response_headers; + return $this->responseHeaders; } /** @@ -52,7 +57,18 @@ class ApiException extends Exception { * @return string HTTP response body */ public function getResponseBody() { - return $this->response_body; + return $this->responseBody; } + /** + * sets the deseralized response object (during deserialization) + * @param mixed $obj + */ + public function setResponseObject($obj) { + $this->responseObject = $obj; + } + + public function getResponseObject() { + return $this->responseObject; + } } diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index b6f17f528d5..3d9ead4bed1 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -140,16 +140,14 @@ class {{classname}} { $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { - $throw = $e; - switch ($e->getCode()) { {{#responses}}{{#dataType}} case {{code}}: $data = ObjectSerializer::deserialize($e->getResponseBody(), '{{dataType}}'); - $throw = new ApiException("{{message}}", $e->getCode(), $e->getResponseHeaders(), $data); + $e->setResponseObject($data); break;{{/dataType}}{{/responses}} } - throw $throw; + throw $e; } {{#returnType}} if (!$response) {