-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patherror.php
More file actions
47 lines (42 loc) · 1.59 KB
/
error.php
File metadata and controls
47 lines (42 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
use OpenRuntimes\Executor\HttpException;
use Utopia\Http\Http;
use Utopia\Http\Response;
use Utopia\System\System;
Http::error()
->inject('error')
->inject('response')
->action(function (Throwable $error, Response $response): void {
if ($error instanceof HttpException) {
if ($error->publish) {
// TODO: publish to logger/Sentry
}
$code = $error->statusCode;
$output = [
'type' => $error->type,
'message' => $error->getMessage(),
'code' => $code,
'version' => System::getEnv('OPR_EXECUTOR_VERSION', 'unknown'),
];
} else {
// TODO: always publish to logger/Sentry
$code = 500;
$output = [
'type' => 'general_unknown',
'message' => Http::isDevelopment() ? $error->getMessage() : 'Internal server error.',
'code' => 500,
'version' => System::getEnv('OPR_EXECUTOR_VERSION', 'unknown'),
];
}
if (Http::isDevelopment()) {
$output['file'] = $error->getFile();
$output['line'] = $error->getLine();
$output['trace'] = \json_encode($error->getTrace(), JSON_UNESCAPED_UNICODE) === false ? [] : $error->getTrace();
}
$response
->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate')
->addHeader('Expires', '0')
->addHeader('Pragma', 'no-cache')
->setStatusCode($code)
->json($output);
});