(body)
| 72 | : type |
| 73 | |
| 74 | function parse (body) { |
| 75 | if (body.length === 0) { |
| 76 | // special-case empty json body, as it's a common client-side mistake |
| 77 | // TODO: maybe make this configurable or part of "strict" option |
| 78 | return {} |
| 79 | } |
| 80 | |
| 81 | if (strict) { |
| 82 | var first = firstchar(body) |
| 83 | |
| 84 | if (first !== '{' && first !== '[') { |
| 85 | debug('strict violation') |
| 86 | throw createStrictSyntaxError(body, first) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | try { |
| 91 | debug('parse json') |
| 92 | return JSON.parse(body, reviver) |
| 93 | } catch (e) { |
| 94 | throw normalizeJsonSyntaxError(e, { |
| 95 | message: e.message, |
| 96 | stack: e.stack |
| 97 | }) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return function jsonParser (req, res, next) { |
| 102 | if (req._body) { |
nothing calls this directly
no test coverage detected