Skip to content

Commit f1e394b

Browse files
committed
fix for #770
1 parent 886145b commit f1e394b

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

dist/lib/swagger-client.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// swagger-client.js
2-
// version 2.1.0-alpha.3
2+
// version 2.1.0-alpha.4
33
/**
44
* Array Model
55
**/
@@ -936,7 +936,7 @@ Operation.prototype.setContentTypes = function(args, opts) {
936936
}
937937

938938
// if there's a body, need to set the accepts header via requestContentType
939-
if (body && (this.type === 'post' || this.type === 'put' || this.type === 'patch' || this.type === 'delete')) {
939+
if (body && (this.method === 'post' || this.method === 'put' || this.method === 'patch' || this.method === 'delete')) {
940940
if (opts.requestContentType)
941941
consumes = opts.requestContentType;
942942
} else {
@@ -1350,7 +1350,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
13501350
obj.data = obj.body;
13511351
obj.complete = function(response, textStatus, opts) {
13521352
var headers = {},
1353-
headerArray = response.getAllResponseHeaders().split("\n");
1353+
headerArray = response.getAllResponseHeaders().split("\n");
13541354

13551355
for(var i = 0; i < headerArray.length; i++) {
13561356
var toSplit = headerArray[i].trim();
@@ -1363,7 +1363,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
13631363
continue;
13641364
}
13651365
var name = toSplit.substring(0, separator).trim(),
1366-
value = toSplit.substring(separator + 1).trim();
1366+
value = toSplit.substring(separator + 1).trim();
13671367
headers[name] = value;
13681368
}
13691369

@@ -1379,8 +1379,15 @@ JQueryHttpClient.prototype.execute = function(obj) {
13791379

13801380
if(contentType != null) {
13811381
if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
1382-
if(response.responseText && response.responseText !== "")
1383-
out.obj = JSON.parse(response.responseText);
1382+
if(response.responseText && response.responseText !== "") {
1383+
try {
1384+
out.obj = JSON.parse(response.content.data);
1385+
}
1386+
catch (ex) {
1387+
// do not set out.obj
1388+
log ("unable to parse JSON content");
1389+
}
1390+
}
13841391
else
13851392
out.obj = {}
13861393
}

lib/swagger-client.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// swagger-client.js
2-
// version 2.1.0-alpha.3
2+
// version 2.1.0-alpha.4
33
/**
44
* Array Model
55
**/
@@ -936,7 +936,7 @@ Operation.prototype.setContentTypes = function(args, opts) {
936936
}
937937

938938
// if there's a body, need to set the accepts header via requestContentType
939-
if (body && (this.type === 'post' || this.type === 'put' || this.type === 'patch' || this.type === 'delete')) {
939+
if (body && (this.method === 'post' || this.method === 'put' || this.method === 'patch' || this.method === 'delete')) {
940940
if (opts.requestContentType)
941941
consumes = opts.requestContentType;
942942
} else {
@@ -1350,7 +1350,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
13501350
obj.data = obj.body;
13511351
obj.complete = function(response, textStatus, opts) {
13521352
var headers = {},
1353-
headerArray = response.getAllResponseHeaders().split("\n");
1353+
headerArray = response.getAllResponseHeaders().split("\n");
13541354

13551355
for(var i = 0; i < headerArray.length; i++) {
13561356
var toSplit = headerArray[i].trim();
@@ -1363,7 +1363,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
13631363
continue;
13641364
}
13651365
var name = toSplit.substring(0, separator).trim(),
1366-
value = toSplit.substring(separator + 1).trim();
1366+
value = toSplit.substring(separator + 1).trim();
13671367
headers[name] = value;
13681368
}
13691369

@@ -1379,8 +1379,15 @@ JQueryHttpClient.prototype.execute = function(obj) {
13791379

13801380
if(contentType != null) {
13811381
if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
1382-
if(response.responseText && response.responseText !== "")
1383-
out.obj = JSON.parse(response.responseText);
1382+
if(response.responseText && response.responseText !== "") {
1383+
try {
1384+
out.obj = JSON.parse(response.content.data);
1385+
}
1386+
catch (ex) {
1387+
// do not set out.obj
1388+
log ("unable to parse JSON content");
1389+
}
1390+
}
13841391
else
13851392
out.obj = {}
13861393
}

0 commit comments

Comments
 (0)