webservice MDL-21511 add webservice_parameter_exception to indicate which external parameter is invalid

This commit is contained in:
jerome mouneyrac
2010-02-05 04:10:36 +00:00
parent 71f61c41f3
commit 559a5dbd1d
3 changed files with 28 additions and 2 deletions
+1
View File
@@ -59,6 +59,7 @@ $string['functions'] = 'Functions';
$string['generalstructure'] = 'General structure';
$string['httpswarning'] = 'Token strings are only displayed if your connection is secured (https)';
$string['information'] = 'Information';
$string['invalidextparam'] = 'Invalid external api parameter: $a';
$string['invalidiptoken'] = 'Invalid token - your IP is not supported';
$string['invalidtimedtoken'] = 'Invalid token - token expired';
$string['invalidtoken'] = 'Invalid token - token not found';
+10 -2
View File
@@ -168,11 +168,19 @@ class external_api {
}
if ($subdesc instanceof external_value) {
if ($subdesc->required == VALUE_DEFAULT) {
$result[$key] = self::validate_parameters($subdesc, $subdesc->default);
try {
$result[$key] = self::validate_parameters($subdesc, $subdesc->default);
} catch (invalid_parameter_exception $e) {
throw new webservice_parameter_exception('invalidextparam',$key);
}
}
}
} else {
$result[$key] = self::validate_parameters($subdesc, $params[$key]);
try {
$result[$key] = self::validate_parameters($subdesc, $params[$key]);
} catch (invalid_parameter_exception $e) {
throw new webservice_parameter_exception('invalidextparam',$key);
}
}
unset($params[$key]);
}
+17
View File
@@ -91,6 +91,23 @@ class moodle_exception extends Exception {
}
}
/**
* Web service parameter exception class
*
* This exception must be thrown to the web service client when a web service parameter is invalid
* The error string is gotten from webservice.php
*/
class webservice_parameter_exception extends moodle_exception {
/**
* Constructor
* @param string $errorcode The name of the string from webservice.php to print
* @param string $a The name of the parameter
*/
function __construct($errorcode=null, $a = '') {
parent::__construct($errorcode, 'webservice', '', $a, null);
}
}
/**
* Exceptions indicating user does not have permissions to do something
* and the execution can not continue.