It is really annoying that the REST API always returns a 200 response code, even if, for example, an action is not allowed. This makes searching the logs and debugging more difficult.
|
/** |
|
* generates a CiviCRM REST API compliant error |
|
* and ends processing |
|
*/ |
|
function civiproxy_rest_error($message) { |
|
$error = array( 'is_error' => 1, |
|
'error_message' => $message); |
|
// TODO: Implement header(); |
|
print json_encode($error); |
|
exit(); |
|
} |
We should do something like this:
/**
* generates a CiviCRM REST API compliant error
* and ends processing
*/
function civiproxy_rest_error($message, $status_code = 500) {
$error = [
'is_error' => 1,
'error_message' => $message,
];
http_response_code($status_code); // Set the HTTP response code
header('Content-Type: application/json'); // Send JSON response header
echo json_encode($error);
exit();
}
It is really annoying that the REST API always returns a 200 response code, even if, for example, an action is not allowed. This makes searching the logs and debugging more difficult.
CiviProxy/proxy/checks.php
Lines 3 to 13 in 0609256
We should do something like this: