Skip to content

Commit

Permalink
Added proper error response (#1814)
Browse files Browse the repository at this point in the history
  • Loading branch information
sredbull authored and wing328 committed Jan 7, 2019
1 parent 1189362 commit eff0c5e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Expand Up @@ -438,7 +438,14 @@ class ApiClient {
{{#usePromises}}return new Promise((resolve, reject) => {
request.end((error, response) => {
if (error) {
reject(error);
var err = {};
err.status = response.status;
err.statusText = response.statusText;
err.body = response.body;
err.response = response;
err.error = error;

reject(err);
} else {
try {
var data = this.deserialize(response, returnType);
Expand Down
22 changes: 21 additions & 1 deletion samples/client/petstore/javascript-promise-es6/src/ApiClient.js
Expand Up @@ -89,6 +89,11 @@ class ApiClient {
*/
this.requestAgent = null;

/*
* Allow user to add superagent plugins
*/
this.plugins = null;

}

/**
Expand Down Expand Up @@ -347,6 +352,14 @@ class ApiClient {
var url = this.buildUrl(path, pathParams);
var request = superagent(httpMethod, url);

if (this.plugins !== null) {
for (var index in this.plugins) {
if (this.plugins.hasOwnProperty(index)) {
request.use(this.plugins[index])
}
}
}

// apply authentications
this.applyAuthToRequest(request, authNames);

Expand Down Expand Up @@ -420,7 +433,14 @@ class ApiClient {
return new Promise((resolve, reject) => {
request.end((error, response) => {
if (error) {
reject(error);
var err = {};
err.status = response.status;
err.statusText = response.statusText;
err.body = response.body;
err.response = response;
err.error = error;

reject(err);
} else {
try {
var data = this.deserialize(response, returnType);
Expand Down

0 comments on commit eff0c5e

Please sign in to comment.