From b8ccbe7392f76e542e5f2c30d8d46f485ba949e3 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 4 Feb 2021 13:15:17 -0800 Subject: [PATCH] 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) --- CRM/Api4/Page/AJAX.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Api4/Page/AJAX.php b/CRM/Api4/Page/AJAX.php index 58400510f7..a368b20c4c 100644 --- a/CRM/Api4/Page/AJAX.php +++ b/CRM/Api4/Page/AJAX.php @@ -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(); -- 2.25.1