Skip to content

Commit 09ff8a6

Browse files
adding continueOnError property for batch operations
1 parent aa05a5f commit 09ff8a6

File tree

9 files changed

+2306
-2263
lines changed

9 files changed

+2306
-2263
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 0 additions & 42 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/README.md

Lines changed: 2219 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/build-test-coverage.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

README.md

Lines changed: 28 additions & 2146 deletions
Large diffs are not rendered by default.

lib/utilities/buildPreferHeader.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var DWA = require('../dwa');
2-
var ErrorHelper = require('../helpers/ErrorHelper');
1+
var DWA = require("../dwa");
2+
var ErrorHelper = require("../helpers/ErrorHelper");
33

44
/**
55
* Builds a Prefer header value
@@ -13,28 +13,28 @@ module.exports = function buildPreferHeader(request, functionName, config) {
1313
var includeAnnotations = request.includeAnnotations;
1414
var maxPageSize = request.maxPageSize;
1515
var trackChanges = request.trackChanges;
16+
var continueOnError = request.continueOnError;
1617

1718
var prefer;
1819

1920
if (request.prefer && request.prefer.length) {
2021
ErrorHelper.stringOrArrayParameterCheck(request.prefer, "DynamicsWebApi." + functionName, "request.prefer");
2122
prefer = request.prefer;
2223
if (typeof prefer === "string") {
23-
prefer = prefer.split(',');
24+
prefer = prefer.split(",");
2425
}
2526
for (var i in prefer) {
2627
var item = prefer[i].trim();
2728
if (item === DWA.Prefer.ReturnRepresentation) {
2829
returnRepresentation = true;
29-
}
30-
else if (item.indexOf("odata.include-annotations=") > -1) {
31-
includeAnnotations = item.replace('odata.include-annotations=', '').replace(/"/g, '');
32-
}
33-
else if (item.startsWith("odata.maxpagesize=")) {
34-
maxPageSize = item.replace('odata.maxpagesize=', '').replace(/"/g, '');
35-
}
36-
else if (item.indexOf("odata.track-changes") > -1) {
30+
} else if (item.indexOf("odata.include-annotations=") > -1) {
31+
includeAnnotations = item.replace("odata.include-annotations=", "").replace(/"/g, "");
32+
} else if (item.startsWith("odata.maxpagesize=")) {
33+
maxPageSize = item.replace("odata.maxpagesize=", "").replace(/"/g, "");
34+
} else if (item.indexOf("odata.track-changes") > -1) {
3735
trackChanges = true;
36+
} else if (item.includes("odata.continue-on-error")) {
37+
continueOnError = true;
3838
}
3939
}
4040
}
@@ -61,13 +61,18 @@ module.exports = function buildPreferHeader(request, functionName, config) {
6161

6262
if (maxPageSize && maxPageSize > 0) {
6363
ErrorHelper.numberParameterCheck(maxPageSize, "DynamicsWebApi." + functionName, "request.maxPageSize");
64-
prefer.push('odata.maxpagesize=' + maxPageSize);
64+
prefer.push("odata.maxpagesize=" + maxPageSize);
6565
}
6666

6767
if (trackChanges) {
6868
ErrorHelper.boolParameterCheck(trackChanges, "DynamicsWebApi." + functionName, "request.trackChanges");
69-
prefer.push('odata.track-changes');
69+
prefer.push("odata.track-changes");
70+
}
71+
72+
if (continueOnError) {
73+
ErrorHelper.boolParameterCheck(continueOnError, "DynamicsWebApi." + functionName, "request.continueOnError");
74+
prefer.push("odata.continue-on-error");
7075
}
7176

72-
return prefer.join(',');
73-
}
77+
return prefer.join(",");
78+
};

tests/common-tests.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,15 @@ describe("RequestConverter.convertRequestOptions -", function () {
878878
expect(result).to.deep.equal({ url: stubUrl, query: "", headers: { Prefer: "odata.maxpagesize=10" } });
879879
});
880880

881+
it("continueOnError", function () {
882+
var dwaRequest = {
883+
continueOnError: true,
884+
};
885+
886+
var result = RequestConverter.convertRequestOptions(dwaRequest, "", stubUrl);
887+
expect(result).to.deep.equal({ url: stubUrl, query: "", headers: { Prefer: "odata.continue-on-error" } });
888+
});
889+
881890
it("navigationProperty empty", function () {
882891
var dwaRequest = {
883892
navigationProperty: "",
@@ -1291,6 +1300,24 @@ describe("RequestConverter.convertRequestOptions -", function () {
12911300
});
12921301
});
12931302

1303+
it("includeAnnotations & returnRepresentation & maxPageSize & continueOnError", function () {
1304+
var dwaRequest = {
1305+
returnRepresentation: true,
1306+
includeAnnotations: "*",
1307+
maxPageSize: 20,
1308+
continueOnError: true
1309+
};
1310+
1311+
var result = RequestConverter.convertRequestOptions(dwaRequest, "", stubUrl);
1312+
expect(result).to.deep.equal({
1313+
url: stubUrl,
1314+
query: "",
1315+
headers: {
1316+
Prefer: DWA.Prefer.ReturnRepresentation + ',odata.include-annotations="*",odata.maxpagesize=20,odata.continue-on-error',
1317+
},
1318+
});
1319+
});
1320+
12941321
it("includeAnnotations & maxPageSize", function () {
12951322
var dwaRequest = {
12961323
includeAnnotations: "*",

types/dynamics-web-api-callbacks.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ declare class DynamicsWebApi {
819819
* @param errorCallback - The function that will be passed through and be called by a failed response.
820820
* @param request
821821
*/
822-
executeBatch(successCallback: Function, errorCallback: Function, request?: DynamicsWebApi.RequestBase): void;
822+
executeBatch(successCallback: Function, errorCallback: Function, request?: DynamicsWebApi.BatchRequest): void;
823823
/**
824824
* Creates a new instance of DynamicsWebApi
825825
*
@@ -868,6 +868,11 @@ declare namespace DynamicsWebApi {
868868
timeout?: number;
869869
}
870870

871+
interface BatchRequest extends RequestBase{
872+
//Sets Prefer header to "odata.continue-on-error" that allows more requests be processed when errors occur. The batch request will return '200 OK' and individual response errors will be returned in the batch response body.
873+
continueOnError?: boolean;
874+
}
875+
871876
interface Request extends RequestBase {
872877
/**The name of the Entity Collection or Entity Logical name. */
873878
collection?: string;

types/dynamics-web-api.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ declare class DynamicsWebApi {
507507
/**
508508
* Executes a batch request. Please call DynamicsWebApi.startBatch() first to start a batch request.
509509
*/
510-
executeBatch(request?: DynamicsWebApi.RequestBase): Promise<any[]>;
510+
executeBatch(request?: DynamicsWebApi.BatchRequest): Promise<any[]>;
511511
/**
512512
* Creates a new instance of DynamicsWebApi
513513
*
@@ -556,6 +556,11 @@ declare namespace DynamicsWebApi {
556556
timeout?: number;
557557
}
558558

559+
interface BatchRequest extends RequestBase{
560+
//Sets Prefer header to "odata.continue-on-error" that allows more requests be processed when errors occur. The batch request will return '200 OK' and individual response errors will be returned in the batch response body.
561+
continueOnError?: boolean;
562+
}
563+
559564
interface Request extends RequestBase {
560565
/**The name of the Entity Collection or Entity Logical name. */
561566
collection?: string;

0 commit comments

Comments
 (0)