Skip to content

Commit 7d87142

Browse files
committed
replace shutdown function with exception handler
1 parent 9cb1f68 commit 7d87142

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

resources/init.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use UnityWebPortal\lib\UnityGithub;
1515
use UnityWebPortal\lib\UnityHTTPD;
1616

17-
register_shutdown_function(array("UnityWebPortal\lib\UnityHTTPD", "shutdown"));
18-
// shutdown function logs errors, don't want duplicate output
17+
set_exception_handler(["UnityWebPortal\lib\UnityHTTPD", "exceptionHandler"]);
18+
// exception handler logs errors, don't want duplicate output
1919
ini_set("log_errors", false);
2020

2121
session_start();

resources/lib/UnityHTTPD.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,10 @@ public static function internalServerError($message, $error = null, $data = null
126126
self::die($message);
127127
}
128128

129-
// https://www.php.net/manual/en/function.register-shutdown-function.php
130-
public static function shutdown()
129+
// https://www.php.net/manual/en/function.set-exception-handler.php
130+
public static function exceptionHandler(\Throwable $e)
131131
{
132-
$e = error_get_last();
133-
if (is_null($e) || $e["type"] !== E_ERROR) {
134-
return;
135-
}
136-
// newlines are bad for error log
137-
if (!is_null($e) && array_key_exists("message", $e) && str_contains($e["message"], "\n")) {
138-
$e["message"] = explode("\n", $e["message"]);
139-
}
140-
// error_get_last is an array, not a Throwable
141-
self::internalServerError("An internal server error has occurred.", data: ["error" => $e]);
132+
self::internalServerError("An internal server error has occurred.", error: $e);
142133
}
143134

144135
public static function getPostData(...$keys)

0 commit comments

Comments
 (0)