pouchdb-ajax
Advanced tools
Comparing version 5.4.4 to 5.4.5
@@ -134,4 +134,3 @@ 'use strict'; | ||
} catch (exception) { | ||
/* error code hardcoded to throw INVALID_URL */ | ||
callback(exception, {statusCode: 413}); | ||
return callback(new Error(exception.name || 'Url is invalid')); | ||
} | ||
@@ -203,5 +202,5 @@ | ||
var err = {}; | ||
if(timedout) { | ||
if (timedout) { | ||
err = new Error('ETIMEDOUT'); | ||
response.statusCode = 400; // for consistency with node request | ||
err.code = 'ETIMEDOUT'; | ||
} else { | ||
@@ -212,3 +211,4 @@ try { | ||
} | ||
callback(err, response); | ||
err.status = xhr.status; | ||
callback(err); | ||
} | ||
@@ -271,2 +271,3 @@ }; | ||
if (!options.binary && options.json && typeof obj === 'string') { | ||
/* istanbul ignore next */ | ||
try { | ||
@@ -294,27 +295,2 @@ obj = JSON.parse(obj); | ||
function onError(err, cb) { | ||
var errParsed, errObj; | ||
if (err.code && err.status) { | ||
var err2 = new Error(err.message || err.code); | ||
err2.status = err.status; | ||
return cb(err2); | ||
} | ||
/* istanbul ignore if */ | ||
if (err.message && err.message === 'ETIMEDOUT') { | ||
return cb(err); | ||
} | ||
// We always get code && status in node | ||
/* istanbul ignore next */ | ||
try { | ||
errParsed = JSON.parse(err.responseText); | ||
//would prefer not to have a try/catch clause | ||
errObj = pouchdbErrors.generateErrorFromResponse(errParsed); | ||
} catch (e) { | ||
errObj = pouchdbErrors.generateErrorFromResponse(err); | ||
} | ||
/* istanbul ignore next */ | ||
cb(errObj); | ||
} | ||
if (options.json) { | ||
@@ -338,5 +314,5 @@ if (!options.binary) { | ||
return ajax$1(options, function (err, response, body) { | ||
if (err) { | ||
err.status = response ? response.statusCode : 400; | ||
return onError(err, callback); | ||
return callback(pouchdbErrors.generateErrorFromResponse(err)); | ||
} | ||
@@ -343,0 +319,0 @@ |
@@ -37,2 +37,3 @@ 'use strict'; | ||
if (!options.binary && options.json && typeof obj === 'string') { | ||
/* istanbul ignore next */ | ||
try { | ||
@@ -60,27 +61,2 @@ obj = JSON.parse(obj); | ||
function onError(err, cb) { | ||
var errParsed, errObj; | ||
if (err.code && err.status) { | ||
var err2 = new Error(err.message || err.code); | ||
err2.status = err.status; | ||
return cb(err2); | ||
} | ||
/* istanbul ignore if */ | ||
if (err.message && err.message === 'ETIMEDOUT') { | ||
return cb(err); | ||
} | ||
// We always get code && status in node | ||
/* istanbul ignore next */ | ||
try { | ||
errParsed = JSON.parse(err.responseText); | ||
//would prefer not to have a try/catch clause | ||
errObj = pouchdbErrors.generateErrorFromResponse(errParsed); | ||
} catch (e) { | ||
errObj = pouchdbErrors.generateErrorFromResponse(err); | ||
} | ||
/* istanbul ignore next */ | ||
cb(errObj); | ||
} | ||
if (options.json) { | ||
@@ -104,5 +80,5 @@ if (!options.binary) { | ||
return request(options, function (err, response, body) { | ||
if (err) { | ||
err.status = response ? response.statusCode : 400; | ||
return onError(err, callback); | ||
return callback(pouchdbErrors.generateErrorFromResponse(err)); | ||
} | ||
@@ -109,0 +85,0 @@ |
{ | ||
"name": "pouchdb-ajax", | ||
"version": "5.4.4", | ||
"version": "5.4.5", | ||
"description": "PouchDB's ajax() method.", | ||
@@ -27,8 +27,8 @@ "main": "./lib/index.js", | ||
"js-extend": "1.0.1", | ||
"pouchdb-binary-utils": "5.4.4", | ||
"pouchdb-errors": "5.4.4", | ||
"pouchdb-promise": "5.4.4", | ||
"pouchdb-utils": "5.4.4", | ||
"pouchdb-binary-utils": "5.4.5", | ||
"pouchdb-errors": "5.4.5", | ||
"pouchdb-promise": "5.4.5", | ||
"pouchdb-utils": "5.4.5", | ||
"request": "2.72.0" | ||
} | ||
} |
@@ -25,2 +25,3 @@ import request from './request'; | ||
if (!options.binary && options.json && typeof obj === 'string') { | ||
/* istanbul ignore next */ | ||
try { | ||
@@ -48,27 +49,2 @@ obj = JSON.parse(obj); | ||
function onError(err, cb) { | ||
var errParsed, errObj; | ||
if (err.code && err.status) { | ||
var err2 = new Error(err.message || err.code); | ||
err2.status = err.status; | ||
return cb(err2); | ||
} | ||
/* istanbul ignore if */ | ||
if (err.message && err.message === 'ETIMEDOUT') { | ||
return cb(err); | ||
} | ||
// We always get code && status in node | ||
/* istanbul ignore next */ | ||
try { | ||
errParsed = JSON.parse(err.responseText); | ||
//would prefer not to have a try/catch clause | ||
errObj = generateErrorFromResponse(errParsed); | ||
} catch (e) { | ||
errObj = generateErrorFromResponse(err); | ||
} | ||
/* istanbul ignore next */ | ||
cb(errObj); | ||
} | ||
if (options.json) { | ||
@@ -92,5 +68,5 @@ if (!options.binary) { | ||
return request(options, function (err, response, body) { | ||
if (err) { | ||
err.status = response ? response.statusCode : 400; | ||
return onError(err, callback); | ||
return callback(generateErrorFromResponse(err)); | ||
} | ||
@@ -97,0 +73,0 @@ |
@@ -129,4 +129,3 @@ /* global fetch */ | ||
} catch (exception) { | ||
/* error code hardcoded to throw INVALID_URL */ | ||
callback(exception, {statusCode: 413}); | ||
return callback(new Error(exception.name || 'Url is invalid')); | ||
} | ||
@@ -198,5 +197,5 @@ | ||
var err = {}; | ||
if(timedout) { | ||
if (timedout) { | ||
err = new Error('ETIMEDOUT'); | ||
response.statusCode = 400; // for consistency with node request | ||
err.code = 'ETIMEDOUT'; | ||
} else { | ||
@@ -207,3 +206,4 @@ try { | ||
} | ||
callback(err, response); | ||
err.status = xhr.status; | ||
callback(err); | ||
} | ||
@@ -210,0 +210,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36107
738
+ Addedpouchdb-binary-utils@5.4.5(transitive)
+ Addedpouchdb-errors@5.4.5(transitive)
+ Addedpouchdb-md5@5.4.5(transitive)
+ Addedpouchdb-promise@5.4.5(transitive)
+ Addedpouchdb-utils@5.4.5(transitive)
- Removedpouchdb-binary-utils@5.4.4(transitive)
- Removedpouchdb-errors@5.4.4(transitive)
- Removedpouchdb-md5@5.4.4(transitive)
- Removedpouchdb-promise@5.4.4(transitive)
- Removedpouchdb-utils@5.4.4(transitive)
Updatedpouchdb-binary-utils@5.4.5
Updatedpouchdb-errors@5.4.5
Updatedpouchdb-promise@5.4.5
Updatedpouchdb-utils@5.4.5