This is a follow-up to #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)
$statusMap = [
\Civi\API\Exception\UnauthorizedException::class => 403,
];
- http_response_code($statusMap[get_class($e) ?? 500]);
+ http_response_code($statusMap[get_class($e)] ?? 500);
$response = [];
if (CRM_Core_Permission::check('view debug output')) {
$response['error_code'] = $e->getCode();