Skip to content

Commit

Permalink
fix(tools): return 422 when invalid json
Browse files Browse the repository at this point in the history
ISSUES CLOSED: freeCodeCamp#175
  • Loading branch information
user512 committed Jan 11, 2019
1 parent af0d5f5 commit 01d3b45
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit 01d3b45

Please sign in to comment.