better exception using InvalidArgumentException

This commit is contained in:
wing328
2015-05-19 16:21:06 +08:00
parent af260cba41
commit 5744bd0138
6 changed files with 18 additions and 18 deletions

View File

@@ -55,7 +55,7 @@ class APIClient {
*/
public function addDefaultHeader($header_name, $header_value) {
if (!is_string($header_name))
throw new exception('heaer name must be a string.');
throw new \InvalidArgumentException('Header name must be a string.');
self::$default_header[$header_name] = $header_value;
}
@@ -85,7 +85,7 @@ class APIClient {
*/
public function setUserAgent($user_agent) {
if (!is_string($user_agent))
throw new exception('user-agent must be a string.');
throw new \InvalidArgumentException('User-agent must be a string.');
$this->user_agent= $user_agent;
}
@@ -95,7 +95,7 @@ class APIClient {
*/
public function setTimeout($seconds) {
if (!is_numeric($seconds))
throw new Exception('Timeout variable must be numeric.');
throw new \InvalidArgumentException('Timeout variable must be numeric.');
$this->curl_timeout = $seconds;
}
@@ -167,7 +167,7 @@ class APIClient {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method != self::$GET) {
throw new Exception('Method ' . $method . ' is not recognized.');
throw new APIClientException('Method ' . $method . ' is not recognized.');
}
curl_setopt($curl, CURLOPT_URL, $url);

View File

@@ -42,7 +42,7 @@ class {{classname}} {
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if (${{paramName}} === null) {
throw new \Exception("Missing the required parameter ${{paramName}} when calling {{nickname}}");
throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}');
}
{{/required}}{{/allParams}}

View File

@@ -55,7 +55,7 @@ class APIClient {
*/
public function addDefaultHeader($header_name, $header_value) {
if (!is_string($header_name))
throw new exception('heaer name must be a string.');
throw new \InvalidArgumentException('Header name must be a string.');
self::$default_header[$header_name] = $header_value;
}
@@ -85,7 +85,7 @@ class APIClient {
*/
public function setUserAgent($user_agent) {
if (!is_string($user_agent))
throw new exception('user-agent must be a string.');
throw new \InvalidArgumentException('User-agent must be a string.');
$this->user_agent= $user_agent;
}
@@ -95,7 +95,7 @@ class APIClient {
*/
public function setTimeout($seconds) {
if (!is_numeric($seconds))
throw new Exception('Timeout variable must be numeric.');
throw new \InvalidArgumentException('Timeout variable must be numeric.');
$this->curl_timeout = $seconds;
}
@@ -167,7 +167,7 @@ class APIClient {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method != self::$GET) {
throw new Exception('Method ' . $method . ' is not recognized.');
throw new APIClientException('Method ' . $method . ' is not recognized.');
}
curl_setopt($curl, CURLOPT_URL, $url);

View File

@@ -255,7 +255,7 @@ class PetApi {
// verify the required parameter 'pet_id' is set
if ($pet_id === null) {
throw new \Exception("Missing the required parameter $pet_id when calling getPetById");
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetById');
}
@@ -319,7 +319,7 @@ class PetApi {
// verify the required parameter 'pet_id' is set
if ($pet_id === null) {
throw new \Exception("Missing the required parameter $pet_id when calling updatePetWithForm");
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling updatePetWithForm');
}
@@ -382,7 +382,7 @@ class PetApi {
// verify the required parameter 'pet_id' is set
if ($pet_id === null) {
throw new \Exception("Missing the required parameter $pet_id when calling deletePet");
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling deletePet');
}
@@ -443,7 +443,7 @@ class PetApi {
// verify the required parameter 'pet_id' is set
if ($pet_id === null) {
throw new \Exception("Missing the required parameter $pet_id when calling uploadFile");
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling uploadFile');
}

View File

@@ -150,7 +150,7 @@ class StoreApi {
// verify the required parameter 'order_id' is set
if ($order_id === null) {
throw new \Exception("Missing the required parameter $order_id when calling getOrderById");
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById');
}
@@ -212,7 +212,7 @@ class StoreApi {
// verify the required parameter 'order_id' is set
if ($order_id === null) {
throw new \Exception("Missing the required parameter $order_id when calling deleteOrder");
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder');
}

View File

@@ -300,7 +300,7 @@ class UserApi {
// verify the required parameter 'username' is set
if ($username === null) {
throw new \Exception("Missing the required parameter $username when calling getUserByName");
throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName');
}
@@ -363,7 +363,7 @@ class UserApi {
// verify the required parameter 'username' is set
if ($username === null) {
throw new \Exception("Missing the required parameter $username when calling updateUser");
throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser');
}
@@ -423,7 +423,7 @@ class UserApi {
// verify the required parameter 'username' is set
if ($username === null) {
throw new \Exception("Missing the required parameter $username when calling deleteUser");
throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser');
}