feat: log plugin runtime errors
This commit is contained in:
+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']));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user