diff --git a/app/http.php b/app/http.php index a3df530..03fdbb9 100644 --- a/app/http.php +++ b/app/http.php @@ -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 @@ -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