$request['id']] : []; return [ 'jsonrpc' => '2.0', 'result' => $result, ] + $id; } /** * Create a response object (unsuccessful). * * @link https://www.jsonrpc.org/specification#response_object * @param array{jsonrpc: string, method: string, params: array, id: ?mixed} $request * @param \Throwable $t * The exception which caused the request to fail. * @return array{jsonrpc: string, error: array, id: ?mixed} */ public static function createResponseError(array $request, \Throwable $t): array { $isJsonErrorCode = $t->getCode() >= -32999 && $t->getCode() <= -32000; $errorData = \CRM_Core_Config::singleton()->debug ? ['class' => get_class($t), 'trace' => $t->getTraceAsString()] : NULL; $id = array_key_exists('id', $request) ? ['id' => $request['id']] : []; return [ 'jsonrpc' => $request['jsonrpc'] ?? '2.0', 'error' => [ 'code' => $isJsonErrorCode ? $t->getCode() : -32099, 'message' => $t->getMessage(), 'data' => $errorData, ], ] + $id; } }