Skip to content

Commit

Permalink
feat: create a parseJSON method that parses json encoded request bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
teclone committed Jul 20, 2018
1 parent 569e2e1 commit ae4508a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/modules/BodyParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,20 @@ export default class {
target[name] = value;
}
}

/**
* parse json content
*@param {string} string - the request body string
*@returns {Object}
*/
parseJSON(string) {
let body = null;
try {
body = JSON.parse(string);
}
catch(ex) {
body = {};
}
return body;
}
}

0 comments on commit ae4508a

Please sign in to comment.