further enhanced error handling + added retries in case of parallel writes
This commit is contained in:
@ -15,15 +15,7 @@ case 'GET':
|
||||
$bundle = qdb_export_translations_bundle($pdo);
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
} catch (Throwable $e) {
|
||||
if (isset($tmpDb, $lockFp)) {
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
}
|
||||
if (function_exists('qdb_api_log_note_exception')) {
|
||||
qdb_api_log_note_exception($e);
|
||||
}
|
||||
require_once __DIR__ . '/../lib/errors.php';
|
||||
error_log('translations exportBundle: ' . $e->getMessage());
|
||||
json_error('SERVER_ERROR', qdb_public_error_message($e, 'Export'), 500);
|
||||
qdb_handler_fail($e, 'Export translations', null, $tmpDb ?? null, $lockFp ?? null);
|
||||
}
|
||||
|
||||
$filename = 'translations_bundle_' . date('Y-m-d_His') . '.json';
|
||||
@ -41,15 +33,7 @@ case 'GET':
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
json_success(['languages' => $rows]);
|
||||
} catch (Throwable $e) {
|
||||
if (isset($tmpDb, $lockFp)) {
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
}
|
||||
if (function_exists('qdb_api_log_note_exception')) {
|
||||
qdb_api_log_note_exception($e);
|
||||
}
|
||||
require_once __DIR__ . '/../lib/errors.php';
|
||||
error_log('translations languages: ' . $e->getMessage());
|
||||
json_error('SERVER_ERROR', qdb_public_error_message($e, 'Load languages'), 500);
|
||||
qdb_handler_fail($e, 'Load languages', null, $tmpDb ?? null, $lockFp ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,15 +86,7 @@ case 'GET':
|
||||
'sourceLanguage' => QDB_SOURCE_LANGUAGE,
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
if (isset($tmpDb, $lockFp)) {
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
}
|
||||
if (function_exists('qdb_api_log_note_exception')) {
|
||||
qdb_api_log_note_exception($e);
|
||||
}
|
||||
require_once __DIR__ . '/../lib/errors.php';
|
||||
error_log('translations all: ' . $e->getMessage());
|
||||
json_error('SERVER_ERROR', qdb_public_error_message($e, 'Load translations'), 500);
|
||||
qdb_handler_fail($e, 'Load translations', null, $tmpDb ?? null, $lockFp ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,15 +122,7 @@ case 'GET':
|
||||
'sourceLanguage' => QDB_SOURCE_LANGUAGE,
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
if (isset($tmpDb, $lockFp)) {
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
}
|
||||
if (function_exists('qdb_api_log_note_exception')) {
|
||||
qdb_api_log_note_exception($e);
|
||||
}
|
||||
require_once __DIR__ . '/../lib/errors.php';
|
||||
error_log('translations questionnaire: ' . $e->getMessage());
|
||||
json_error('SERVER_ERROR', qdb_public_error_message($e, 'Load translations'), 500);
|
||||
qdb_handler_fail($e, 'Load translations', null, $tmpDb ?? null, $lockFp ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,15 +160,7 @@ case 'GET':
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
json_success(['translations' => $rows]);
|
||||
} catch (Throwable $e) {
|
||||
if (isset($tmpDb, $lockFp)) {
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
}
|
||||
if (function_exists('qdb_api_log_note_exception')) {
|
||||
qdb_api_log_note_exception($e);
|
||||
}
|
||||
require_once __DIR__ . '/../lib/errors.php';
|
||||
error_log('translations GET: ' . $e->getMessage());
|
||||
json_error('SERVER_ERROR', qdb_public_error_message($e, 'Load translations'), 500);
|
||||
qdb_handler_fail($e, 'Load translations', null, $tmpDb ?? null, $lockFp ?? null);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -212,20 +172,13 @@ case 'POST':
|
||||
if (!is_array($bundle)) {
|
||||
json_error('MISSING_FIELDS', 'bundle object is required', 400);
|
||||
}
|
||||
[$pdo, $tmpDb, $lockFp] = qdb_open(true);
|
||||
[$pdo, $tmpDb, $lockFp] = qdb_open_write_or_fail();
|
||||
try {
|
||||
$result = qdb_import_translations_bundle($pdo, $bundle);
|
||||
qdb_save($tmpDb, $lockFp);
|
||||
json_success($result);
|
||||
} catch (Throwable $e) {
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
error_log('translations importBundle: ' . $e->getMessage());
|
||||
require_once __DIR__ . '/../lib/errors.php';
|
||||
if (function_exists('qdb_api_log_note_exception')) {
|
||||
qdb_api_log_note_exception($e);
|
||||
}
|
||||
error_log('translations importBundle: ' . $e->getMessage());
|
||||
json_error('SERVER_ERROR', qdb_public_error_message($e, 'Import'), 500);
|
||||
qdb_handler_fail($e, 'Import translations', null, $tmpDb, $lockFp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -243,7 +196,7 @@ case 'PUT':
|
||||
if (!$lang) {
|
||||
json_error('MISSING_FIELDS', 'languageCode required', 400);
|
||||
}
|
||||
[$pdo, $tmpDb, $lockFp] = qdb_open(true);
|
||||
[$pdo, $tmpDb, $lockFp] = qdb_open_write_or_fail();
|
||||
try {
|
||||
if ($lang === QDB_SOURCE_LANGUAGE) {
|
||||
qdb_ensure_source_language($pdo);
|
||||
@ -255,9 +208,7 @@ case 'PUT':
|
||||
qdb_save($tmpDb, $lockFp);
|
||||
json_success([]);
|
||||
} catch (Throwable $e) {
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
error_log($e->getMessage());
|
||||
json_error('SERVER_ERROR', 'Server error', 500);
|
||||
qdb_handler_fail($e, 'Save language', null, $tmpDb, $lockFp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -280,15 +231,7 @@ case 'PUT':
|
||||
qdb_save($tmpDb, $lockFp);
|
||||
json_success([]);
|
||||
} catch (Throwable $e) {
|
||||
if (isset($tmpDb, $lockFp)) {
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
}
|
||||
if (function_exists('qdb_api_log_note_exception')) {
|
||||
qdb_api_log_note_exception($e);
|
||||
}
|
||||
require_once __DIR__ . '/../lib/errors.php';
|
||||
error_log('translations PUT: ' . $e->getMessage());
|
||||
json_error('SERVER_ERROR', qdb_public_error_message($e, 'Save translation'), 500);
|
||||
qdb_handler_fail($e, 'Save translation', null, $tmpDb ?? null, $lockFp ?? null);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -305,7 +248,7 @@ case 'DELETE':
|
||||
if ($lang === QDB_SOURCE_LANGUAGE) {
|
||||
json_error('BAD_REQUEST', 'German (de) cannot be removed', 400);
|
||||
}
|
||||
[$pdo, $tmpDb, $lockFp] = qdb_open(true);
|
||||
[$pdo, $tmpDb, $lockFp] = qdb_open_write_or_fail();
|
||||
try {
|
||||
$pdo->prepare("DELETE FROM language WHERE languageCode = :lc")->execute([':lc' => $lang]);
|
||||
$pdo->prepare("DELETE FROM question_translation WHERE languageCode = :lc")->execute([':lc' => $lang]);
|
||||
@ -314,9 +257,7 @@ case 'DELETE':
|
||||
qdb_save($tmpDb, $lockFp);
|
||||
json_success([]);
|
||||
} catch (Throwable $e) {
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
error_log($e->getMessage());
|
||||
json_error('SERVER_ERROR', 'Server error', 500);
|
||||
qdb_handler_fail($e, 'Delete language', null, $tmpDb, $lockFp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -349,15 +290,7 @@ case 'DELETE':
|
||||
qdb_save($tmpDb, $lockFp);
|
||||
json_success([]);
|
||||
} catch (Throwable $e) {
|
||||
if (isset($tmpDb, $lockFp)) {
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
}
|
||||
if (function_exists('qdb_api_log_note_exception')) {
|
||||
qdb_api_log_note_exception($e);
|
||||
}
|
||||
require_once __DIR__ . '/../lib/errors.php';
|
||||
error_log('translations DELETE: ' . $e->getMessage());
|
||||
json_error('SERVER_ERROR', qdb_public_error_message($e, 'Delete translation'), 500);
|
||||
qdb_handler_fail($e, 'Delete translation', null, $tmpDb ?? null, $lockFp ?? null);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user