From 4a0cb3475eea8b5e5eeb5b87c82ab91e31907332 Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Thu, 17 Dec 2020 02:46:35 +0100 Subject: [PATCH] Return errors when rule parsing is bad --- src/database/database.ts | 4 ++-- src/web/v1/admin.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/database/database.ts b/src/database/database.ts index dd191da..d4d06fe 100644 --- a/src/database/database.ts +++ b/src/database/database.ts @@ -145,7 +145,7 @@ export class Database { rawRules = "service realtimedb {\n match /* {\n allow read, write, list: if false; \n }\n}"; // still json, so switching to - } catch (err) {} + } catch (err) { } let { runner, error } = compileRule(rawRules); if (error) { @@ -157,7 +157,7 @@ export class Database { return undefined; } - async setRules(rawRules: string) { + async setRules(rawRules: string): Promise { const { runner, error } = compileRule(rawRules); if (error) return error; await Settings.setDatabaseRules(this.name, rawRules); diff --git a/src/web/v1/admin.ts b/src/web/v1/admin.ts index f5806d9..40ce1c2 100644 --- a/src/web/v1/admin.ts +++ b/src/web/v1/admin.ts @@ -112,7 +112,14 @@ AdminRoute.get("/database", (ctx) => { if (publickey) await db.setPublicKey(publickey); - if (rules) await db.setRules(rules); + if (rules) { + const error = await db.setRules(rules); + if (error) { + ctx.status = 500; + ctx.body = error; + return; + } + } if (accesskey) await db.setAccessKey(accesskey);