From cc0a087a709c33488b2f41930f90840268b9fcee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 13 Dec 2021 19:19:56 -0500 Subject: [PATCH] fix: prevent crash if groups is not valid json --- src/navigation/admin.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/navigation/admin.js b/src/navigation/admin.js index 19193abdc7..e4221bf156 100644 --- a/src/navigation/admin.js +++ b/src/navigation/admin.js @@ -1,6 +1,7 @@ 'use strict'; const validator = require('validator'); +const winston = require('winston'); const plugins = require('../plugins'); const db = require('../database'); @@ -66,7 +67,12 @@ admin.get = async function () { const data = await db.getObjects(ids.map(id => `navigation:enabled:${id}`)); cache = data.map((item) => { if (item.hasOwnProperty('groups')) { - item.groups = JSON.parse(item.groups); + try { + item.groups = JSON.parse(item.groups); + } catch (err) { + winston.error(err.stack); + item.groups = []; + } } item.groups = item.groups || []; if (item.groups && !Array.isArray(item.groups)) {