From 01d3b453cdeb49007dd5e49409ce4db16393a8d2 Mon Sep 17 00:00:00 2001 From: Tom Lee Date: Thu, 10 Jan 2019 20:55:25 -0800 Subject: [PATCH] fix(tools): return 422 when invalid json ISSUES CLOSED: #175 --- src/handler.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/handler.js b/src/handler.js index 47d8bde..f009031 100644 --- a/src/handler.js +++ b/src/handler.js @@ -66,6 +66,18 @@ exports.graphqlHandler = async function graphqlHandler( process.exit(); /* eslint-enable no-process-exit */ } + + try { + JSON.parse(event.body); + } catch (err) { + const msg = 'Invalid JSON'; + log(msg, err); + return callback(null, { + body: msg, + statusCode: 422 + }); + } + return handler(event, context, callbackFilter); };