mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 17:06:53 +02:00
MDL-63225 webservice: Return proper debuginfo on WS exceptions
In order to make developers easy, we should give some clues about the type of the data generating exceptions.
This commit is contained in:
parent
5211af1658
commit
86196f93fb
2 changed files with 23 additions and 1 deletions
|
@ -380,8 +380,9 @@ class external_api {
|
||||||
return (bool)$response;
|
return (bool)$response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$responsetype = gettype($response);
|
||||||
$debuginfo = 'Invalid external api response: the value is "' . $response .
|
$debuginfo = 'Invalid external api response: the value is "' . $response .
|
||||||
'", the server was expecting "' . $description->type . '" type';
|
'" of PHP type "' . $responsetype . '", the server was expecting "' . $description->type . '" type';
|
||||||
try {
|
try {
|
||||||
return validate_param($response, $description->type, $description->allownull, $debuginfo);
|
return validate_param($response, $description->type, $description->allownull, $debuginfo);
|
||||||
} catch (invalid_parameter_exception $e) {
|
} catch (invalid_parameter_exception $e) {
|
||||||
|
|
|
@ -256,6 +256,27 @@ class core_externallib_testcase extends advanced_testcase {
|
||||||
$settings->set_filter($currentfilter);
|
$settings->set_filter($currentfilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for clean_returnvalue() for testing that returns the PHP type.
|
||||||
|
*/
|
||||||
|
public function test_clean_returnvalue_return_php_type() {
|
||||||
|
|
||||||
|
$returndesc = new external_single_structure(
|
||||||
|
array(
|
||||||
|
'value' => new external_value(PARAM_RAW, 'Some text', VALUE_OPTIONAL, null, NULL_NOT_ALLOWED)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check return type on exception because the external values does not allow NULL values.
|
||||||
|
$testdata = array('value' => null);
|
||||||
|
try {
|
||||||
|
$cleanedvalue = external_api::clean_returnvalue($returndesc, $testdata);
|
||||||
|
} catch (moodle_exception $e) {
|
||||||
|
$this->assertInstanceOf('invalid_response_exception', $e);
|
||||||
|
$this->assertContains('of PHP type "NULL"', $e->debuginfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for clean_returnvalue().
|
* Test for clean_returnvalue().
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue