feat: log plugin runtime errors
This commit is contained in:
@@ -18,6 +18,7 @@ return static function (AppContext $ctx): void {
|
||||
}
|
||||
Http::redirect($ctx->url('index.html', ['status' => 'created']));
|
||||
} catch (Throwable $e) {
|
||||
PluginLogger::exception($e, 'CREATE');
|
||||
$errors[] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ return static function (AppContext $ctx): void {
|
||||
$ctx->audit->record('delete', $ctx->daUser->username(), ['rule_id' => $id, 'subject_prefix' => (string)($rule['subject_prefix'] ?? $rule['subject'] ?? '')]);
|
||||
Http::redirect($ctx->url('index.html', ['status' => 'deleted']));
|
||||
} catch (Throwable $e) {
|
||||
PluginLogger::exception($e, 'DELETE');
|
||||
$ctx->render('Confirm deletion', '<div class="alert alert-err">' . AppContext::e($e->getMessage()) . '</div>');
|
||||
return;
|
||||
}
|
||||
|
||||
+16
-11
@@ -2,16 +2,21 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
return static function (AppContext $ctx): void {
|
||||
$ctx->requirePost();
|
||||
$id = $ctx->post('id');
|
||||
$ctx->requireCsrf('toggle:' . $id);
|
||||
$rule = $ctx->rules->find($ctx->daUser->username(), $id);
|
||||
if ($rule === null) {
|
||||
throw new RuntimeException($ctx->t('Rule not found'));
|
||||
try {
|
||||
$ctx->requirePost();
|
||||
$id = $ctx->post('id');
|
||||
$ctx->requireCsrf('toggle:' . $id);
|
||||
$rule = $ctx->rules->find($ctx->daUser->username(), $id);
|
||||
if ($rule === null) {
|
||||
throw new RuntimeException($ctx->t('Rule not found'));
|
||||
}
|
||||
$next = ['enabled' => empty($rule['enabled'])];
|
||||
enforce_rule_backend_constraints($ctx, $id, $next);
|
||||
$ctx->rules->update($ctx->daUser->username(), $id, $next);
|
||||
$ctx->syncActiveBackend();
|
||||
Http::redirect($ctx->url('index.html', ['status' => 'toggled']));
|
||||
} catch (Throwable $e) {
|
||||
PluginLogger::exception($e, 'TOGGLE');
|
||||
throw $e;
|
||||
}
|
||||
$next = ['enabled' => empty($rule['enabled'])];
|
||||
enforce_rule_backend_constraints($ctx, $id, $next);
|
||||
$ctx->rules->update($ctx->daUser->username(), $id, $next);
|
||||
$ctx->syncActiveBackend();
|
||||
Http::redirect($ctx->url('index.html', ['status' => 'toggled']));
|
||||
};
|
||||
|
||||
@@ -19,6 +19,7 @@ return static function (AppContext $ctx): void {
|
||||
$ctx->syncActiveBackend();
|
||||
Http::redirect($ctx->url('index.html', ['status' => 'updated']));
|
||||
} catch (Throwable $e) {
|
||||
PluginLogger::exception($e, 'UPDATE');
|
||||
$errors[] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user