Skip to content

Commit eff0c5e

Browse files
sredbullwing328
authored andcommitted
Added proper error response (#1814)
1 parent 1189362 commit eff0c5e

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,14 @@ class ApiClient {
438438
{{#usePromises}}return new Promise((resolve, reject) => {
439439
request.end((error, response) => {
440440
if (error) {
441-
reject(error);
441+
var err = {};
442+
err.status = response.status;
443+
err.statusText = response.statusText;
444+
err.body = response.body;
445+
err.response = response;
446+
err.error = error;
447+
448+
reject(err);
442449
} else {
443450
try {
444451
var data = this.deserialize(response, returnType);

samples/client/petstore/javascript-promise-es6/src/ApiClient.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ class ApiClient {
8989
*/
9090
this.requestAgent = null;
9191

92+
/*
93+
* Allow user to add superagent plugins
94+
*/
95+
this.plugins = null;
96+
9297
}
9398

9499
/**
@@ -347,6 +352,14 @@ class ApiClient {
347352
var url = this.buildUrl(path, pathParams);
348353
var request = superagent(httpMethod, url);
349354

355+
if (this.plugins !== null) {
356+
for (var index in this.plugins) {
357+
if (this.plugins.hasOwnProperty(index)) {
358+
request.use(this.plugins[index])
359+
}
360+
}
361+
}
362+
350363
// apply authentications
351364
this.applyAuthToRequest(request, authNames);
352365

@@ -420,7 +433,14 @@ class ApiClient {
420433
return new Promise((resolve, reject) => {
421434
request.end((error, response) => {
422435
if (error) {
423-
reject(error);
436+
var err = {};
437+
err.status = response.status;
438+
err.statusText = response.statusText;
439+
err.body = response.body;
440+
err.response = response;
441+
err.error = error;
442+
443+
reject(err);
424444
} else {
425445
try {
426446
var data = this.deserialize(response, returnType);

0 commit comments

Comments
 (0)