further enhanced error handling + added retries in case of parallel writes
This commit is contained in:
@ -16,7 +16,7 @@ $body = read_json_body();
|
||||
$action = trim((string)($body['action'] ?? 'import'));
|
||||
|
||||
try {
|
||||
[$pdo, $tmpDb, $lockFp] = qdb_open(true);
|
||||
[$pdo, $tmpDb, $lockFp] = qdb_open_write_or_fail();
|
||||
|
||||
if ($action === 'remove') {
|
||||
$result = qdb_remove_dev_test_data($pdo, [
|
||||
@ -43,20 +43,11 @@ try {
|
||||
qdb_save($tmpDb, $lockFp);
|
||||
json_success($result);
|
||||
} catch (Throwable $e) {
|
||||
if (isset($tmpDb, $lockFp)) {
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
}
|
||||
$labels = [
|
||||
'remove' => 'Remove',
|
||||
'wipeExceptAdmins' => 'Wipe',
|
||||
'import' => 'Import',
|
||||
'remove' => 'Remove dev data',
|
||||
'wipeExceptAdmins' => 'Wipe database',
|
||||
'import' => 'Import dev fixture',
|
||||
];
|
||||
$label = $labels[$action ?? 'import'] ?? 'Operation';
|
||||
error_log("dev fixture $label: " . $e->getMessage());
|
||||
require_once __DIR__ . '/../lib/errors.php';
|
||||
if (function_exists('qdb_api_log_note_exception')) {
|
||||
qdb_api_log_note_exception($e);
|
||||
}
|
||||
error_log("dev fixture $label: " . $e->getMessage());
|
||||
json_error('SERVER_ERROR', qdb_public_error_message($e, $label), 500);
|
||||
$label = $labels[$action ?? 'import'] ?? 'Dev fixture';
|
||||
qdb_handler_fail($e, $label, $pdo ?? null, $tmpDb ?? null, $lockFp ?? null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user