Skip to content

Commit a987e8b

Browse files
committed
Check if documents property is undefined for a resource PUT or POST
1 parent 0f90f95 commit a987e8b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/resources-exec.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var Operation = require('./operation.js');
2222
* Provides functions to execute resource services on the REST server
2323
* for the client. The resource service extensions must have been
2424
* installed previously on the REST server using the
25-
* {@link config.resources#write} function.
25+
* {@link config.resources#write} function.
2626
* @namespace resources
2727
*/
2828

@@ -229,8 +229,10 @@ function writeResources(self, method, responseType, args) {
229229
};
230230

231231
var partList = [];
232-
for (var i=0; i < documents.length; i++) {
233-
addPart(partList, documents[i]);
232+
if (typeof documents !== 'undefined') {
233+
for (var i=0; i < documents.length; i++) {
234+
addPart(partList, documents[i]);
235+
}
234236
}
235237

236238
var operation = new Operation(
@@ -271,7 +273,7 @@ function addPart(partList, document) {
271273
headers['Content-Type'] = 'text/plain';
272274
} else if (Buffer.isBuffer(document)) {
273275
part.content = document;
274-
headers['Content-Type'] = 'application/x-unknown-content-type';
276+
headers['Content-Type'] = 'application/x-unknown-content-type';
275277
} else {
276278
part.content = JSON.stringify(document);
277279
// headers['Content-Type'] = 'application/json; charset=utf-8';

0 commit comments

Comments
 (0)