APIv4 - AJAX errors should say *something* useful
authorTim Otten <totten@civicrm.org>
Thu, 4 Feb 2021 03:46:49 +0000 (19:46 -0800)
committerTim Otten <totten@civicrm.org>
Thu, 4 Feb 2021 04:18:32 +0000 (20:18 -0800)
commit2af6f9b6cf8ee02ec14769de1de9a245ff3edc34
tree46e56b472d2765d3db1417b8b4177e9ad70408f9
parent2514c69b1764c244fa270f608c70bdfe99445ba7
APIv4 - AJAX errors should say *something* useful

When calling APIv4 via AJAX, you may sometimes encounter an error. What response do you get?

Before
------

You are likely to get a completely blank response (`status=500, body=[]`).
There is no information in any of the logs (Apache, PHP, CiviCRM, etc).  You
have no way to tell what's gone wrong.

Of course, if you're logged in as a full administrator, then you may have
permission `view debug output`, in which case there might be something
useful.  But this won't help if you're using a less privileged user.

After
-----

For the administrator (`view debug output`), you still get a detailed error response.

For less privileged users, the error is logged. The response provides a generic message along with an
"Error ID". You can use the "Error ID" to locate information in the log.

Also, if the error is an `UnauthorizedException`, then the response code will be a semantic 403 instead of a generic 500.
CRM/Api4/Page/AJAX.php