diff --git a/modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache index 15cc588f06b4..fd4fb57e7d95 100644 --- a/modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache @@ -372,7 +372,7 @@ class ApiClient { * @param {Array.} accepts An array of acceptable response MIME types. * @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the * constructor for a complex type. - * @param {String} apiBasePath base path defined in the operation/path level to override the default one + * @param {String} apiBasePath base path defined in the operation/path level to override the default one {{^usePromises}} * @param {module:{{#invokerPackage}}{{invokerPackage}}/{{/invokerPackage}}ApiClient~callApiCallback} callback The callback function. {{/usePromises}} @@ -469,10 +469,12 @@ class ApiClient { request.end((error, response) => { if (error) { var err = {}; - err.status = response.status; - err.statusText = response.statusText; - err.body = response.body; - err.response = response; + if (response) { + err.status = response.status; + err.statusText = response.statusText; + err.body = response.body; + err.response = response; + } err.error = error; reject(err); diff --git a/samples/client/petstore/javascript-promise-es6/src/ApiClient.js b/samples/client/petstore/javascript-promise-es6/src/ApiClient.js index 828ec6b5c9c5..dc4ff8062266 100644 --- a/samples/client/petstore/javascript-promise-es6/src/ApiClient.js +++ b/samples/client/petstore/javascript-promise-es6/src/ApiClient.js @@ -355,7 +355,7 @@ class ApiClient { * @param {Array.} accepts An array of acceptable response MIME types. * @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the * constructor for a complex type. - * @param {String} apiBasePath base path defined in the operation/path level to override the default one + * @param {String} apiBasePath base path defined in the operation/path level to override the default one * @returns {Promise} A {@link https://www.promisejs.org/|Promise} object. */ callApi(path, httpMethod, pathParams, @@ -447,10 +447,12 @@ class ApiClient { request.end((error, response) => { if (error) { var err = {}; - err.status = response.status; - err.statusText = response.statusText; - err.body = response.body; - err.response = response; + if (response) { + err.status = response.status; + err.statusText = response.statusText; + err.body = response.body; + err.response = response; + } err.error = error; reject(err);