diff --git a/lib/cradle.js b/lib/cradle.js index b21d5ef..5537c7e 100644 --- a/lib/cradle.js +++ b/lib/cradle.js @@ -217,20 +217,16 @@ cradle.Connection.prototype.request = function (options, callback) { else if (options.method === 'HEAD') { return callback(null, res.headers, res.statusCode); } - else if (body && body.error) { - cradle.extend(body, { headers: res.headers }); - body.headers.status = res.statusCode; - return callback(new cradle.CouchError(body)); - } - - try { body = JSON.parse(body) } - catch (err) { } - - if (body && body.error) { - cradle.extend(body, { headers: res.headers }); - body.headers.status = res.statusCode; - return callback(new cradle.CouchError(body)); + else if (body) { + try { body = JSON.parse(body); } + catch (error) { } + if (body.error) { + cradle.extend(body, { headers: res.headers }); + body.headers.status = res.statusCode; + return callback(new cradle.CouchError(body)); + } } + callback(null, self.options.raw ? body : new cradle.Response(body, res)); });