forked from loafle/openapi-generator-original
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:
parent
109b7eeaec
commit
01d7776fc1
@ -24,17 +24,22 @@ class ApiException extends Exception {
|
|||||||
/**
|
/**
|
||||||
* The HTTP body of the server response.
|
* The HTTP body of the server response.
|
||||||
*/
|
*/
|
||||||
protected $response_body;
|
protected $responseBody;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The HTTP header of the server response.
|
* 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) {
|
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) {
|
||||||
parent::__construct($message, $code);
|
parent::__construct($message, $code);
|
||||||
$this->response_headers = $responseHeaders;
|
$this->responseHeaders = $responseHeaders;
|
||||||
$this->response_body = $responseBody;
|
$this->responseBody = $responseBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,7 +48,7 @@ class ApiException extends Exception {
|
|||||||
* @return string HTTP response header
|
* @return string HTTP response header
|
||||||
*/
|
*/
|
||||||
public function getResponseHeaders() {
|
public function getResponseHeaders() {
|
||||||
return $this->response_headers;
|
return $this->responseHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,7 +57,18 @@ class ApiException extends Exception {
|
|||||||
* @return string HTTP response body
|
* @return string HTTP response body
|
||||||
*/
|
*/
|
||||||
public function getResponseBody() {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,16 +140,14 @@ class {{classname}} {
|
|||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
$throw = $e;
|
|
||||||
|
|
||||||
switch ($e->getCode()) { {{#responses}}{{#dataType}}
|
switch ($e->getCode()) { {{#responses}}{{#dataType}}
|
||||||
case {{code}}:
|
case {{code}}:
|
||||||
$data = ObjectSerializer::deserialize($e->getResponseBody(), '{{dataType}}');
|
$data = ObjectSerializer::deserialize($e->getResponseBody(), '{{dataType}}');
|
||||||
$throw = new ApiException("{{message}}", $e->getCode(), $e->getResponseHeaders(), $data);
|
$e->setResponseObject($data);
|
||||||
break;{{/dataType}}{{/responses}}
|
break;{{/dataType}}{{/responses}}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw $throw;
|
throw $e;
|
||||||
}
|
}
|
||||||
{{#returnType}}
|
{{#returnType}}
|
||||||
if (!$response) {
|
if (!$response) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user