JSON encoding fails silently, so if it fails for whatever reason, the user will get red error text, e.g. Internal error when calling loadForumThread, but nothing shows up in the error log. This means people could be getting that kind of error message all the time, and we have no way of knowing unless they complain.
Proposed fix:
header('Content-Type: application/json');
echo json_encode($output);
$last_error = json_last_error();
if ($last_error) {
error_log("API call with spec: " . var_export($args, TRUE) . " yielded a JSON error: " . $last_error);
}
If we made that change, we'd be notified via error log whenever someone didn't get their API response.
json_last_error_msg() might be even better, depending; i think it's just the string version of the static integer error, so it's not going to make our logs vulnerable or anything.
This is something i discovered during testing around #2974 but is worth addressing independently.
The ApiResponder.php code which returns API responses to the user ends with:
JSON encoding fails silently, so if it fails for whatever reason, the user will get red error text, e.g.
Internal error when calling loadForumThread
, but nothing shows up in the error log. This means people could be getting that kind of error message all the time, and we have no way of knowing unless they complain.Proposed fix:
If we made that change, we'd be notified via error log whenever someone didn't get their API response.