Refactor execute method to improve API response handling

This commit is contained in:
Torsten Dittmann
2025-05-18 15:13:54 +02:00
parent 5493488216
commit dbe8382d2e
+16 -8
View File
@@ -98,18 +98,26 @@ class Executor
$endpoint = $this->selectEndpoint($projectId, $deploymentId);
$body = '';
$response = $this->call($endpoint, self::METHOD_POST, $route, [ 'x-opr-runtime-id' => $runtimeId ], $params, true, $timeout, callback: function ($chunk) use (&$body) {
$body .= $chunk;
});
$response = '';
$this->call(
$endpoint,
self::METHOD_POST,
$route,
[ 'x-opr-runtime-id' => $runtimeId ],
$params,
true,
$timeout,
callback: fn ($chunk) => $response .= $chunk
);
$response = json_decode($response, true);
$status = $respomse['code'] ?? 201;
$status = $response['headers']['status-code'];
if ($status >= 400) {
$message = \is_string($response['body']) ? $response['body'] : $response['body']['message'];
throw new \Exception($message, $status);
throw new \Exception($response['message'], $status);
}
return $body;
return $response;
}
/**