mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Refactor execute method to improve API response handling
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user