Skip to content

Commit

Permalink
Merge pull request #103 from open-runtimes/update-error-handling
Browse files Browse the repository at this point in the history
Update error handling
  • Loading branch information
christyjacob4 authored Sep 13, 2024
2 parents eb4537c + 0adc420 commit 7002ad7
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,12 @@ function (string $runtimeId, ?string $payload, string $path, string $method, arr
->action(function (?Route $route, Throwable $error, ?Logger $logger, Response $response, Log $log) {
logError($log, $error, "httpError", $logger, $route);

$version = Http::getEnv('OPR_EXECUTOR_VERSION', 'UNKNOWN');
$message = $error->getMessage();
$file = $error->getFile();
$line = $error->getLine();
$trace = $error->getTrace();

switch ($error->getCode()) {
case 400: // Error allowed publicly
case 401: // Error allowed publicly
Expand All @@ -1233,13 +1239,17 @@ function (string $runtimeId, ?string $payload, string $path, string $method, arr
$code = 500; // All other errors get the generic 500 server error status code
}

$output = [
'message' => $error->getMessage(),
'code' => $error->getCode(),
'file' => $error->getFile(),
'line' => $error->getLine(),
'trace' => $error->getTrace(),
'version' => Http::getEnv('OPR_EXECUTOR_VERSION', 'UNKNOWN')
$output = Http::isDevelopment() ? [
'message' => $message,
'code' => $code,
'file' => $file,
'line' => $line,
'trace' => \json_encode($trace, JSON_UNESCAPED_UNICODE) === false ? [] : $trace, // check for failing encode
'version' => $version
] : [
'message' => $message,
'code' => $code,
'version' => $version
];

$response
Expand Down

0 comments on commit 7002ad7

Please sign in to comment.