Fix stock-out boot, transfer 500, Clear buttons and uncaught engine errors
Return JSON from any uncaught engine exception, stop the empty stock-out warehouse list aborting page boot, reject non-transfer rows in the transfer lookup, define the missing reset_input helper, and remove a stale unreferenced copy of confirm_order.php.
This commit is contained in:
@@ -7,6 +7,34 @@ ini_set('display_errors', 0);
|
||||
ini_set('log_errors', 1);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
// Last-resort handler for exceptions an engine does not catch itself. Many
|
||||
// engines call a manager with no try/catch, so any exception — including the
|
||||
// managers' own deliberate validation messages — used to end as a PHP fatal
|
||||
// with an empty 500 body, which the browser could only report as "Server
|
||||
// error occurred." This mirrors the convention the catching engines already
|
||||
// use: a manager's Exception carries a user-facing message (400); a database
|
||||
// or engine fault stays generic (500) and goes to the server log.
|
||||
set_exception_handler(function (Throwable $e) {
|
||||
while (ob_get_level() > 0) ob_end_clean();
|
||||
if (!headers_sent()) header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
if ($e instanceof PDOException) {
|
||||
error_log('Uncaught PDOException: ' . $e->getMessage() . ' @ ' . $e->getFile() . ':' . $e->getLine());
|
||||
http_response_code(500);
|
||||
$message = 'Database error, please try again.';
|
||||
} elseif ($e instanceof Exception) {
|
||||
http_response_code(400);
|
||||
$message = $e->getMessage();
|
||||
} else {
|
||||
// Error / TypeError: a programming fault, not something to show users.
|
||||
error_log('Uncaught ' . get_class($e) . ': ' . $e->getMessage() . ' @ ' . $e->getFile() . ':' . $e->getLine());
|
||||
http_response_code(500);
|
||||
$message = 'Server error occurred.';
|
||||
}
|
||||
|
||||
echo json_encode(['success' => 0, 'message' => $message]);
|
||||
});
|
||||
|
||||
require_once __DIR__."/../../config.php";
|
||||
require_once __DIR__."/../../dbconn.php";
|
||||
require_once __DIR__."/db_helpers.php";
|
||||
|
||||
Reference in New Issue
Block a user