From 19736bb0b02a34835cf1d1adb7209b63d4e363cd Mon Sep 17 00:00:00 2001 From: DIALLO Mamadou Bobo Date: Wed, 11 May 2016 17:38:13 -0700 Subject: [PATCH] Better checking for response content. Currently, it is assumed that the only reason a 4xx response could be returned is for 400 errors. However if a service is rate limited this result in a crash. This should fix that. --- lib/librato.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/librato.js b/lib/librato.js index edd08f3..2957b86 100644 --- a/lib/librato.js +++ b/lib/librato.js @@ -91,9 +91,9 @@ var post_payload = function(options, proto, payload, retry) } if (/^application\/json/.test(res.headers['content-type'])) { var meta = JSON.parse(d), - fields = meta.errors.params.type, re = /'([^']+)' is a \S+, but was submitted as different type/; - if (fields && fields.length) { + if (meta.errors && meta.errors.params && meta.errors.params.type.length) { + var fields = meta.errors.params.type; for (var i=0; i < fields.length; i++) { var match = re.exec(fields[i]), field = match && match[1];