-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
APIv4 - AJAX errors should say *something* useful #19526
Conversation
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.
(Standard links)
|
This seems fine to me MOP |
$statusMap = [ | ||
\Civi\API\Exception\UnauthorizedException::class => 403, | ||
]; | ||
http_response_code($statusMap[get_class($e) ?? 500]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@totten this code looks incorrect - it is defaulting to the array key 500
but the array does not contain that key.
I think it should be
http_response_code($statusMap[get_class($e) ?? 500]); | |
http_response_code($statusMap[get_class($e)] ?? 500); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a follow-up to civicrm#19526 which addresses a typo that causes a misbehavior in reporting the HTTP status code. Before ------ If an API request encounters an exception, then it always returns HTTP 403. After ----- If an API request encounters an exception, then: * It may return HTTP 403 (for an authorization exception) * It may return HTTP 500 (for any other/unrecognized exception)
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.