mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 00:49:02 +00:00
Abstract error sanitization
This commit is contained in:
parent
462a2d505d
commit
e21f53f4c7
1 changed files with 26 additions and 42 deletions
|
|
@ -243,24 +243,10 @@ class Migrations extends Action
|
|||
*/
|
||||
protected function updateMigrationDocument(Document $migration, Document $project, Realtime $queueForRealtime): Document
|
||||
{
|
||||
$messages = [];
|
||||
|
||||
$errors = $migration->getAttribute('errors', []);
|
||||
foreach ($errors as $error) {
|
||||
$decoded = \json_decode($error, true);
|
||||
if (\is_array($decoded)) {
|
||||
if (isset($decoded['trace'])) {
|
||||
unset($decoded['trace']);
|
||||
}
|
||||
$messages[] = json_encode($decoded);
|
||||
} else {
|
||||
$messages[] = $error;
|
||||
}
|
||||
}
|
||||
|
||||
$migration->setAttribute('errors', $messages);
|
||||
|
||||
/** Trigger Realtime Events */
|
||||
$errors = $this->sanitizeErrors($errors, []);
|
||||
$migration->setAttribute('errors', $errors);
|
||||
|
||||
$queueForRealtime
|
||||
->setProject($project)
|
||||
->setSubscribers(['console', $project->getId()])
|
||||
|
|
@ -380,18 +366,7 @@ class Migrations extends Action
|
|||
$migration->setAttribute('status', 'failed');
|
||||
$migration->setAttribute('stage', 'finished');
|
||||
|
||||
$errors = [];
|
||||
foreach ([...$sourceErrors, ...$destinationErrors] as $error) {
|
||||
$encoded = \json_decode(\json_encode($error), true);
|
||||
if (\is_array($encoded)) {
|
||||
if (isset($encoded['trace'])) {
|
||||
unset($encoded['trace']);
|
||||
}
|
||||
$errors[] = \json_encode($encoded);
|
||||
} else {
|
||||
$errors[] = \json_encode($error);
|
||||
}
|
||||
}
|
||||
$errors = $this->sanitizeErrors($sourceErrors, $destinationErrors);
|
||||
|
||||
$migration->setAttribute('errors', $errors);
|
||||
return;
|
||||
|
|
@ -419,19 +394,7 @@ class Migrations extends Action
|
|||
if ($transfer) {
|
||||
$sourceErrors = $source->getErrors();
|
||||
$destinationErrors = $destination->getErrors();
|
||||
|
||||
$errors = [];
|
||||
foreach ([...$sourceErrors, ...$destinationErrors] as $error) {
|
||||
$encoded = \json_decode(\json_encode($error), true);
|
||||
if (\is_array($encoded)) {
|
||||
if (isset($encoded['trace'])) {
|
||||
unset($encoded['trace']);
|
||||
}
|
||||
$errors[] = \json_encode($encoded);
|
||||
} else {
|
||||
$errors[] = \json_encode($error);
|
||||
}
|
||||
}
|
||||
$errors = $this->sanitizeErrors($sourceErrors, $destinationErrors);
|
||||
|
||||
$migration->setAttribute('errors', $errors);
|
||||
}
|
||||
|
|
@ -472,6 +435,27 @@ class Migrations extends Action
|
|||
}
|
||||
}
|
||||
|
||||
protected function sanitizeErrors(
|
||||
array $sourceErrors,
|
||||
array $destinationErrors,
|
||||
): array
|
||||
{
|
||||
$errors = [];
|
||||
foreach ([...$sourceErrors, ...$destinationErrors] as $error) {
|
||||
$encoded = \json_decode(\json_encode($error), true);
|
||||
if (\is_array($encoded)) {
|
||||
if (isset($encoded['trace'])) {
|
||||
unset($encoded['trace']);
|
||||
}
|
||||
$errors[] = \json_encode($encoded);
|
||||
} else {
|
||||
$errors[] = \json_encode($error);
|
||||
}
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
protected function handleCSVExportComplete(Document $project, Document $migration, Mail $queueForMails): void
|
||||
{
|
||||
$options = $migration->getAttribute('options', []);
|
||||
|
|
|
|||
Loading…
Reference in a new issue