mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
Provide a better error message when a user enters a Conduit parameter string
without quotes around it (and similar) Summary: See D1010. The API uniformly requires JSON, which is good for strictness and predictablity but can be bad for UEX, especially considering that we silently continue after failing to decode things. Toss the user a lifeline when they make this common mistake. Test Plan: Ran API calls with invalid and valid inputs. Invalid inputs gave me a reasonable error message. Reviewers: davidreuss, jungejason, nh, tuomaspelkonen, aran Reviewed By: nh CC: aran, nh Differential Revision: 1012
This commit is contained in:
parent
13eee1a344
commit
abb39d06a2
1 changed files with 16 additions and 1 deletions
|
@ -67,7 +67,22 @@ class PhabricatorConduitAPIController
|
|||
if (isset($_REQUEST['params']) && is_array($_REQUEST['params'])) {
|
||||
$params_post = $request->getArr('params');
|
||||
foreach ($params_post as $key => $value) {
|
||||
$params_post[$key] = json_decode($value, true);
|
||||
$decoded_value = json_decode($value, true);
|
||||
if ($decoded_value === null && strtolower($value) != 'null') {
|
||||
// When json_decode() fails, it returns null. This almost certainly
|
||||
// indicates that a user was using the web UI and didn't put quotes
|
||||
// around a string value. We can either do what we think they meant
|
||||
// (treat it as a string) or fail. For now, err on the side of
|
||||
// caution and fail. In the future, if we make the Conduit API
|
||||
// actually do type checking, it might be reasonable to treat it as
|
||||
// a string if the parameter type is string.
|
||||
throw new Exception(
|
||||
"The value for parameter '{$key}' is not valid JSON. All ".
|
||||
"parameters must be encoded as JSON values, including strings ".
|
||||
"(which means you need to surround them in double quotes). ".
|
||||
"Check your syntax. Value was: {$value}");
|
||||
}
|
||||
$params_post[$key] = $decoded_value;
|
||||
}
|
||||
$params = $params_post;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue