don't create a new response object, and keep the old string value in the exception and have the object as ApiException->responseObject

This commit is contained in:
nmonterroso 2015-06-22 11:47:23 -07:00
parent 109b7eeaec
commit 01d7776fc1
2 changed files with 24 additions and 10 deletions

View File

@ -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;
}
}

View File

@ -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) {