Skip to content

Commit

Permalink
Mejorada la pantalla de error: ahora también muestra si hay errores r…
Browse files Browse the repository at this point in the history
…elacionados con la codificación de json.
  • Loading branch information
NeoRazorX committed Dec 18, 2023
1 parent e4bdef5 commit 486689e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Core/CrashReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function getErrorInfo(int $code, string $message, string $file, in
{
// calculamos un hash para el error, de forma que en la web podamos dar respuesta automáticamente
$errorUrl = parse_url($_SERVER["REQUEST_URI"] ?? '', PHP_URL_PATH);
$errorMessage = self::cleanErrorMessage($message);
$errorMessage = self::formatErrorMessage($message);
$errorFile = str_replace(FS_FOLDER, '', $file);
$errorHash = md5($code . $errorFile . $line . $errorMessage);
$reportUrl = 'https://facturascripts.com/errores/' . $errorHash;
Expand Down Expand Up @@ -148,14 +148,15 @@ public static function shutdown(): void
$num = 1;
$trace = explode("\n", $messageParts[1]);
foreach (array_reverse($trace) as $value) {
if (trim($value) === 'thrown') {
if (trim($value) === 'thrown' || substr($value, 3) === '{main}') {
continue;
}

echo '<tr><td>' . $num . '</td><td>' . substr($value, 3) . '</td></tr>';
$num++;
}

echo '<tr><td>' . $num . '</td><td>' . $info['file'] . ':' . $info['line'] . '</td></tr>';
echo '</tbody></table></div>';
}

Expand Down Expand Up @@ -200,9 +201,21 @@ public static function validateToken(string $token): bool
return $token === self::newToken();
}

private static function cleanErrorMessage(string $message): string
private static function formatErrorMessage(string $message): string
{
return str_replace([FS_FOLDER, 'Stack trace:'], ['', "\nStack trace:"], $message);
// quitamos el folder de las rutas
$message = str_replace(FS_FOLDER, '', $message);

// partimos por la traza
$messageParts = explode("Stack trace:", $message);

// si hay error de json, lo añadimos al mensaje
if (json_last_error()) {
$messageParts[0] .= "\n" . json_last_error_msg();
}

// ahora volvemos a unir el mensaje
return implode("\nStack trace:", $messageParts);
}

private static function trans(string $code): string
Expand Down

0 comments on commit 486689e

Please sign in to comment.