Re-applies change: Add responseHeaders errors #46, and fixes a few additional typos.
This commit is contained in:
Родитель
df9446ec11
Коммит
b2cf8c7573
|
@ -9,10 +9,23 @@ var Base = require("documentdb").Base
|
|||
, DocumentBase = require("documentdb").DocumentBase
|
||||
, Q = require("q");
|
||||
|
||||
function addOrMergeHeadersForError(error, responseHeaders){
|
||||
if (!error.responseHeaders) {
|
||||
error.responseHeaders = responseHeaders;
|
||||
} else {
|
||||
for (k in responseHeaders) {
|
||||
if (!error.responseHeaders[k]) {
|
||||
error.responseHeaders[k] = responseHeaders[k];
|
||||
} // else you lose it because we don't overwrite existing...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createOperationPromise(contextObject, functionName, parentLink, body, options){
|
||||
var deferred = Q.defer();
|
||||
var cb = function (error, resource, responseHeaders) {
|
||||
if (error) {
|
||||
addOrMergeHeadersForError(error, responseHeaders);
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
deferred.resolve({resource: resource, headers: responseHeaders});
|
||||
|
@ -32,6 +45,7 @@ function deleteOperationPromise(contextObject, functionName, resourceLink, optio
|
|||
var deferred = Q.defer();
|
||||
contextObject[functionName](resourceLink, options, function (error, resource, responseHeaders) {
|
||||
if (error) {
|
||||
addOrMergeHeadersForError(error, responseHeaders);
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
deferred.resolve({resource: resource, headers: responseHeaders});
|
||||
|
@ -45,6 +59,7 @@ function replaceOperationPromise(contextObject, functionName, resourceLink, newR
|
|||
var deferred = Q.defer();
|
||||
var callback = function (error, resource, responseHeaders) {
|
||||
if (error) {
|
||||
addOrMergeHeadersForError(error, responseHeaders);
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
deferred.resolve({ resource: resource, headers: responseHeaders });
|
||||
|
@ -64,6 +79,7 @@ function readOperationPromise(contextObject, functionName, resourceLink, options
|
|||
var deferred = Q.defer();
|
||||
var callback = function (error, resource, responseHeaders) {
|
||||
if (error) {
|
||||
addOrMergeHeadersForError(error, responseHeaders);
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
deferred.resolve({ resource: resource, headers: responseHeaders });
|
||||
|
@ -83,6 +99,7 @@ function noParameterPromise(contextObject, functionName, resourceLink){
|
|||
var deferred = Q.defer();
|
||||
contextObject[functionName](resourceLink, function (error, resources, responseHeaders) {
|
||||
if (error) {
|
||||
addOrMergeHeadersForError(error, responseHeaders);
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
deferred.resolve({result: resources, headers: responseHeaders});
|
||||
|
@ -96,6 +113,7 @@ function readFeedOperationPromise(contextObject, functionName, query, options, s
|
|||
var deferred = Q.defer();
|
||||
contextObject[functionName](query, options, function (error, resources, responseHeaders) {
|
||||
if (error) {
|
||||
addOrMergeHeadersForError(error, responseHeaders);
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
deferred.resolve(successFn(resources), responseHeaders);
|
||||
|
@ -137,6 +155,7 @@ var QueryIteratorWrapper = Base.defineClass(
|
|||
var that = this;
|
||||
this._innerQueryIterator.toArray(function (error, resources, responseHeaders) {
|
||||
if (error) {
|
||||
addOrMergeHeadersForError(error, responseHeaders);
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
deferred.resolve({ feed: resources, headers: responseHeaders });
|
||||
|
@ -157,6 +176,7 @@ var QueryIteratorWrapper = Base.defineClass(
|
|||
var that = this;
|
||||
this._innerQueryIterator.nextItem(function (error, item, responseHeaders) {
|
||||
if (error) {
|
||||
addOrMergeHeadersForError(error, responseHeaders);
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
deferred.resolve({ resource: item, headers: responseHeaders });
|
||||
|
@ -177,6 +197,7 @@ var QueryIteratorWrapper = Base.defineClass(
|
|||
var that = this;
|
||||
this._innerQueryIterator.executeNext(function (error, resources, responseHeaders) {
|
||||
if (error) {
|
||||
addOrMergeHeadersForError(error, responseHeaders);
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
deferred.resolve({ feed: resources, headers: responseHeaders });
|
||||
|
@ -1052,6 +1073,7 @@ var DocumentClientWrapper = Base.defineClass(
|
|||
var deferred = Q.defer();
|
||||
this._innerDocumentclient.executeStoredProcedure(sprocLink, params, function (error, result, responseHeaders) {
|
||||
if (error) {
|
||||
addOrMergeHeadersForError(error, responseHeaders);
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
deferred.resolve({result: result, headers: responseHeaders});
|
||||
|
|
|
@ -16,7 +16,7 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|||
var host = testConfig.host;
|
||||
var masterKey = testConfig.masterKey;
|
||||
|
||||
describe("NodeJS Client Q prmise Wrapper CRUD Tests", function(){
|
||||
describe("NodeJS Client Q promise Wrapper CRUD Tests", function(){
|
||||
|
||||
function validateCRUDAsync(client, parentLink, options) {
|
||||
var deferred = Q.defer();
|
||||
|
@ -90,7 +90,7 @@ describe("NodeJS Client Q prmise Wrapper CRUD Tests", function(){
|
|||
})
|
||||
.fail(function (error) {
|
||||
console.log("error", error, error.stack);
|
||||
assert.fail("", "", "an error occured");
|
||||
assert.fail("", "", "an error occurred");
|
||||
deferred.reject(error);
|
||||
});
|
||||
|
||||
|
@ -375,7 +375,7 @@ describe("NodeJS Client Q prmise Wrapper CRUD Tests", function(){
|
|||
return client.readMediaAsync(validAttachment.media);
|
||||
}).then(function (response) {
|
||||
readMediaResponse(response.result, function (err, mediaResult) {
|
||||
assert.equal(err, undefined, "error reading redia response");
|
||||
assert.equal(err, undefined, "error reading media response");
|
||||
assert.equal(mediaResult, "modified first chunk modified second chunk");
|
||||
done();
|
||||
});
|
||||
|
@ -666,12 +666,12 @@ describe("NodeJS Client Q prmise Wrapper CRUD Tests", function(){
|
|||
done();
|
||||
})
|
||||
.fail(function(error){
|
||||
console.log("An error has occured", error, error.stack);
|
||||
console.log("An error has occurred", error, error.stack);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.fail(function(error){
|
||||
console.log("An error has occured", error, error.stack);
|
||||
console.log("An error has occurred", error, error.stack);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -686,7 +686,7 @@ describe("NodeJS Client Q prmise Wrapper CRUD Tests", function(){
|
|||
// test queryIterator.forEach
|
||||
queryIterator.forEach(function(err, doc) {
|
||||
if (err) {
|
||||
console.log("an error occured", err, err.stack);
|
||||
console.log("an error occurred", err, err.stack);
|
||||
return done();
|
||||
}
|
||||
|
||||
|
@ -706,7 +706,7 @@ describe("NodeJS Client Q prmise Wrapper CRUD Tests", function(){
|
|||
});
|
||||
})
|
||||
.fail(function(error){
|
||||
console.log("An error has occured", error, error.stack);
|
||||
console.log("An error has occurred", error, error.stack);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -741,12 +741,12 @@ describe("NodeJS Client Q prmise Wrapper CRUD Tests", function(){
|
|||
done();
|
||||
})
|
||||
.fail(function(error){
|
||||
console.log("An error has occured", error, error.stack);
|
||||
console.log("An error has occurred", error, error.stack);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.fail(function(error){
|
||||
console.log("An error has occured", error, error.stack);
|
||||
console.log("An error has occurred", error, error.stack);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -771,12 +771,12 @@ describe("NodeJS Client Q prmise Wrapper CRUD Tests", function(){
|
|||
done();
|
||||
})
|
||||
.fail(function(error){
|
||||
console.log("An error has occured", error, error.stack);
|
||||
console.log("An error has occurred", error, error.stack);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.fail(function(error){
|
||||
console.log("An error has occured", error, error.stack);
|
||||
console.log("An error has occurred", error, error.stack);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -887,13 +887,13 @@ describe("NodeJS Client Q prmise Wrapper CRUD Tests", function(){
|
|||
})
|
||||
.fail(function(error) {
|
||||
console.log("error", error, error.stack);
|
||||
assert.fail("", "", "an error occured");
|
||||
assert.fail("", "", "an error occurred");
|
||||
done();
|
||||
});
|
||||
})
|
||||
.fail(function(error) {
|
||||
console.log("error", error, error.stack);
|
||||
assert.fail("", "", "an error occured");
|
||||
assert.fail("", "", "an error occurred");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -946,12 +946,12 @@ describe("NodeJS Client Q prmise Wrapper CRUD Tests", function(){
|
|||
done();
|
||||
}).fail(function(error) {
|
||||
console.log("error", error, error.stack);
|
||||
assert.fail("", "", "an error occured");
|
||||
assert.fail("", "", "an error occurred");
|
||||
done();
|
||||
});
|
||||
}).fail(function(error) {
|
||||
console.log("error", error, error.stack);
|
||||
assert.fail("", "", "an error occured");
|
||||
assert.fail("", "", "an error occurred");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче