From 089a1b295c4942b6a91ab298d79c2a54633ec50c Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Wed, 23 Nov 2022 09:41:48 +0100 Subject: [PATCH] Improve Executor client error handling --- app/workers/functions.php | 5 +---- src/Executor/Executor.php | 6 ++++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/workers/functions.php b/app/workers/functions.php index 2333cb315e..56baaf9d1e 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -84,7 +84,7 @@ Server::setResource('execute', function () { 'functionId' => $functionId, 'deploymentId' => $deploymentId, 'trigger' => $trigger, - 'status' => 'waiting', + 'status' => 'processing', 'statusCode' => 0, 'response' => '', 'stderr' => '', @@ -99,9 +99,6 @@ Server::setResource('execute', function () { } } - $execution->setAttribute('status', 'processing'); - $execution = $dbForProject->updateDocument('executions', $executionId, $execution); - $vars = array_reduce($function->getAttribute('vars', []), function (array $carry, Document $var) { $carry[$var->getAttribute('key')] = $var->getAttribute('value'); return $carry; diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 5ca738c302..b8b1e8b4bf 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -94,7 +94,8 @@ class Executor $status = $response['headers']['status-code']; if ($status >= 400) { - throw new \Exception($response['body']['message'], $status); + $message = \is_string($response['body'] ? $response['body'] : $response['body']['message']); + throw new \Exception($message, $status); } return $response['body']; @@ -146,7 +147,8 @@ class Executor $status = $response['headers']['status-code']; if ($status >= 400) { - throw new \Exception($response['body']['message'], $status); + $message = \is_string($response['body'] ? $response['body'] : $response['body']['message']); + throw new \Exception($message, $status); } return $response['body'];