Skip to content
Snippets Groups Projects
Commit b8ccbe73 authored by totten's avatar totten
Browse files

APIv4 - Fix HTTP status code selection

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)
parent 69bb8c7f
Branches
Tags
No related merge requests found
......@@ -84,7 +84,7 @@ class CRM_Api4_Page_AJAX extends CRM_Core_Page {
$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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment