Return errors when rule parsing is bad
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Fabian Stamm 2020-12-17 02:46:35 +01:00
parent b220c223ef
commit 4a0cb3475e
2 changed files with 10 additions and 3 deletions

View File

@ -145,7 +145,7 @@ export class Database {
rawRules = rawRules =
"service realtimedb {\n match /* {\n allow read, write, list: if false; \n }\n}"; "service realtimedb {\n match /* {\n allow read, write, list: if false; \n }\n}";
// still json, so switching to // still json, so switching to
} catch (err) {} } catch (err) { }
let { runner, error } = compileRule(rawRules); let { runner, error } = compileRule(rawRules);
if (error) { if (error) {
@ -157,7 +157,7 @@ export class Database {
return undefined; return undefined;
} }
async setRules(rawRules: string) { async setRules(rawRules: string): Promise<RuleError | undefined> {
const { runner, error } = compileRule(rawRules); const { runner, error } = compileRule(rawRules);
if (error) return error; if (error) return error;
await Settings.setDatabaseRules(this.name, rawRules); await Settings.setDatabaseRules(this.name, rawRules);

View File

@ -112,7 +112,14 @@ AdminRoute.get("/database", (ctx) => {
if (publickey) await db.setPublicKey(publickey); 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); if (accesskey) await db.setAccessKey(accesskey);