-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.php
More file actions
38 lines (33 loc) · 1.08 KB
/
utils.php
File metadata and controls
38 lines (33 loc) · 1.08 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
<?php
function dd(...$values) {
throwError(400, $values);
}
function throwError($code, $body) {
http_response_code($code || 500);
echo json_encode(['body' => $body]);
exit;
}
function customErrorHandler($errno, $errstr, $errfile, $errline) {
error_log("Error [$errno]: $errstr in $errfile on line $errline", 3, 'errors.log');
http_response_code(500);
echo json_encode(['body' => "[$errno]: $errstr in $errfile on line $errline"]);
exit();
}
set_error_handler("customErrorHandler");
function customExceptionHandler($exception) {
error_log("Exception: " . $exception->getMessage(), 3, 'errors.log');
http_response_code(500);
echo json_encode(['body' => $exception->getMessage()]);
exit();
}
set_exception_handler("customExceptionHandler");
function shutdownFunction() {
$error = error_get_last();
if ($error) {
error_log("Exception: " . $error['message'], 3, 'errors.log');
http_response_code(500);
echo json_encode(['body' => $error['message']]);
exit();
}
}
register_shutdown_function('shutdownFunction');