vercel / micro

Asynchronous HTTP microservices
MIT License
10.59k stars 459 forks source link

Unexpected JSON in logger #393

Closed ekkis closed 5 years ago

ekkis commented 5 years ago

I often satisfy lambda requests with:

module.exports = (req, res) => {
    res.end('ok')
}

but that function (defined in log.js), passes it to logResponse as seen below:

    res.end = (chunk, encoding, callback) => {
        res.end = end;
        const endTime = new Date();
        const delta = endTime - start;
        const requestTime =
      delta < 10000 ? `${delta}ms` : `${Math.round(delta / 1000)}s`;
        reqBodyReady.then(() =>
            logResponse({
                res,
                start,
                end: requestTime,
                endTime,
                requestIndex,
                chunk
            }));
        return res.end(chunk, encoding, callback);
    };

which expects to parse it as a JSON object, and that therefore fails

ekkis commented 5 years ago
2019-04-18 02 17 48 pm
ekkis commented 5 years ago

one other note... there is a try/catch around that parse attempt so I guess the code is handling it as it should, but the debugger breaks at that point

ekkis commented 5 years ago

closing this as the problem is actually debugger settings. I needed to turn "All Exceptions" off in the Breakpoints panel in the debugger so this failure doesn't get caught