Skip to content

Commit 4ac2738

Browse files
fabik111wing328
authored andcommitted
[JavaScript][ES6] Fix bug issue #4296 (#4298)
* add check on response * improve check on response * update sample * fix spaces
1 parent 73c55c1 commit 4ac2738

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class ApiClient {
372372
* @param {Array.<String>} accepts An array of acceptable response MIME types.
373373
* @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the
374374
* constructor for a complex type.
375-
* @param {String} apiBasePath base path defined in the operation/path level to override the default one
375+
* @param {String} apiBasePath base path defined in the operation/path level to override the default one
376376
{{^usePromises}}
377377
* @param {module:{{#invokerPackage}}{{invokerPackage}}/{{/invokerPackage}}ApiClient~callApiCallback} callback The callback function.
378378
{{/usePromises}}
@@ -469,10 +469,12 @@ class ApiClient {
469469
request.end((error, response) => {
470470
if (error) {
471471
var err = {};
472-
err.status = response.status;
473-
err.statusText = response.statusText;
474-
err.body = response.body;
475-
err.response = response;
472+
if (response) {
473+
err.status = response.status;
474+
err.statusText = response.statusText;
475+
err.body = response.body;
476+
err.response = response;
477+
}
476478
err.error = error;
477479

478480
reject(err);

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ class ApiClient {
355355
* @param {Array.<String>} accepts An array of acceptable response MIME types.
356356
* @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the
357357
* constructor for a complex type.
358-
* @param {String} apiBasePath base path defined in the operation/path level to override the default one
358+
* @param {String} apiBasePath base path defined in the operation/path level to override the default one
359359
* @returns {Promise} A {@link https://www.promisejs.org/|Promise} object.
360360
*/
361361
callApi(path, httpMethod, pathParams,
@@ -447,10 +447,12 @@ class ApiClient {
447447
request.end((error, response) => {
448448
if (error) {
449449
var err = {};
450-
err.status = response.status;
451-
err.statusText = response.statusText;
452-
err.body = response.body;
453-
err.response = response;
450+
if (response) {
451+
err.status = response.status;
452+
err.statusText = response.statusText;
453+
err.body = response.body;
454+
err.response = response;
455+
}
454456
err.error = error;
455457

456458
reject(err);

0 commit comments

Comments
 (0)