From 163079d2789def01dd89e0c67b80f4467d15f234 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 2 Feb 2021 16:44:31 +0000 Subject: [PATCH] Adding a nicer error for when user input JSON is invalid. --- packages/server/src/api/controllers/query.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/query.js b/packages/server/src/api/controllers/query.js index 5c88a1c121..66de67e093 100644 --- a/packages/server/src/api/controllers/query.js +++ b/packages/server/src/api/controllers/query.js @@ -48,9 +48,13 @@ async function enrichQueryFields(fields, parameters) { } if (enrichedQuery.json || enrichedQuery.customData) { - enrichedQuery.json = JSON.parse( - enrichedQuery.json || enrichedQuery.customData - ) + try { + enrichedQuery.json = JSON.parse( + enrichedQuery.json || enrichedQuery.customData + ) + } catch (err) { + throw { message: `JSON Invalid - error: ${err}` } + } delete enrichedQuery.customData }