From 903e4beab1af1afdc3860110c9739cfaf7df8e5d Mon Sep 17 00:00:00 2001 From: Rich Hodgkins Date: Thu, 24 May 2018 08:58:33 +0100 Subject: [PATCH] Check for undefined when extracting error We've been using this library (npm version v1.0.0) in production and had a few occurrences of: ``` TypeError: Cannot use 'in' operator to search for 'error' in undefined at Function.ResponseHandler.ParseError (ResponseHandler.js:20) at Function.ResponseHandler.init (ResponseHandler.js:14) at (/app/node_modules/@microsoft/microsoft-graph-client/lib/src/GraphRequest.js:191) ``` I've changed the check to ensure the `in` operator is only being used against an object. --- lib/src/ResponseHandler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/ResponseHandler.js b/lib/src/ResponseHandler.js index 0d680db73..9d0313dd4 100644 --- a/lib/src/ResponseHandler.js +++ b/lib/src/ResponseHandler.js @@ -17,7 +17,7 @@ var ResponseHandler = (function () { ResponseHandler.ParseError = function (rawErr) { var errObj; if (!('rawResponse' in rawErr)) { - if (rawErr.response !== undefined && rawErr.response.body !== null && 'error' in rawErr.response.body) { + if (rawErr.response !== undefined && rawErr.response.body !== null && typeof rawErr.response.body === 'object' && 'error' in rawErr.response.body) { errObj = rawErr.response.body.error; } } @@ -54,4 +54,4 @@ var ResponseHandler = (function () { return ResponseHandler; }()); exports.ResponseHandler = ResponseHandler; -//# sourceMappingURL=ResponseHandler.js.map \ No newline at end of file +//# sourceMappingURL=ResponseHandler.js.map