ibm-cloud-sdk-core 4.0.5 → 4.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [4.0.6](https://github.com/IBM/node-sdk-core/compare/v4.0.5...v4.0.6) (2023-05-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * use consistent message for JSON.parse() errors ([#243](https://github.com/IBM/node-sdk-core/issues/243)) ([3cc7bab](https://github.com/IBM/node-sdk-core/commit/3cc7babac6a14b1744d64cf3ab93063b2ce63643))
7
+
1
8
  ## [4.0.5](https://github.com/IBM/node-sdk-core/compare/v4.0.4...v4.0.5) (2023-03-01)
2
9
 
3
10
 
@@ -0,0 +1,26 @@
1
+ /**
2
+ * (C) Copyright IBM Corp. 2023.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Given two Error instances 'error' and 'causedBy', this function will
18
+ * update 'error' by chaining 'causedBy' to it.
19
+ * Specifically, 'causedBy''s message and stack will be appended
20
+ * to 'error''s message and stack, respectively, to simulate chained Errors.
21
+ *
22
+ * @param error the Error object to be updated
23
+ * @param causedBy an Error object that represents the cause of 'error'
24
+ * @returns 'error' after updating its message and stack fields
25
+ */
26
+ export declare function chainError(error: Error, causedBy: Error): Error;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * (C) Copyright IBM Corp. 2023.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Given two Error instances 'error' and 'causedBy', this function will
18
+ * update 'error' by chaining 'causedBy' to it.
19
+ * Specifically, 'causedBy''s message and stack will be appended
20
+ * to 'error''s message and stack, respectively, to simulate chained Errors.
21
+ *
22
+ * @param error the Error object to be updated
23
+ * @param causedBy an Error object that represents the cause of 'error'
24
+ * @returns 'error' after updating its message and stack fields
25
+ */
26
+ export function chainError(error, causedBy) {
27
+ error.message += ` ${causedBy.toString()}`;
28
+ if (causedBy.stack) {
29
+ error.stack += `\nCaused by: ${causedBy.stack}`;
30
+ }
31
+ return error;
32
+ }
@@ -13,11 +13,11 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
16
+ import { InternalAxiosRequestConfig, AxiosResponse } from 'axios';
17
17
  import { CookieJar } from 'tough-cookie';
18
18
  export declare class CookieInterceptor {
19
19
  private readonly cookieJar;
20
20
  constructor(cookieJar: CookieJar | boolean);
21
- requestInterceptor(config: AxiosRequestConfig): Promise<AxiosRequestConfig<any>>;
21
+ requestInterceptor(config: InternalAxiosRequestConfig): Promise<InternalAxiosRequestConfig<any>>;
22
22
  responseInterceptor(response: AxiosResponse): Promise<AxiosResponse<any, any>>;
23
23
  }
@@ -35,6 +35,7 @@ import { buildRequestFileObject, isEmptyObject, isFileData, isFileWithMetadata,
35
35
  import logger from './logger';
36
36
  import { streamToPromise } from './stream-to-promise';
37
37
  import { CookieInterceptor } from './cookie-support';
38
+ import { chainError } from './chain-error';
38
39
  export class RequestWrapper {
39
40
  constructor(axiosOptions) {
40
41
  axiosOptions = axiosOptions || {};
@@ -479,9 +480,9 @@ function ensureJSONResponseBodyIsObject(response) {
479
480
  dataAsObject = JSON.parse(response.data);
480
481
  }
481
482
  catch (e) {
482
- logger.error('Response body was supposed to have JSON content but JSON parsing failed.');
483
- logger.error(`Malformed JSON string: ${response.data}`);
484
- throw e;
483
+ logger.verbose('Response body was supposed to have JSON content but JSON parsing failed.');
484
+ logger.verbose(`Malformed JSON string: ${response.data}`);
485
+ throw chainError(new Error('Error processing HTTP response:'), e);
485
486
  }
486
487
  return dataAsObject;
487
488
  }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * (C) Copyright IBM Corp. 2023.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Given two Error instances 'error' and 'causedBy', this function will
18
+ * update 'error' by chaining 'causedBy' to it.
19
+ * Specifically, 'causedBy''s message and stack will be appended
20
+ * to 'error''s message and stack, respectively, to simulate chained Errors.
21
+ *
22
+ * @param error the Error object to be updated
23
+ * @param causedBy an Error object that represents the cause of 'error'
24
+ * @returns 'error' after updating its message and stack fields
25
+ */
26
+ export declare function chainError(error: Error, causedBy: Error): Error;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /**
3
+ * (C) Copyright IBM Corp. 2023.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.chainError = void 0;
19
+ /**
20
+ * Given two Error instances 'error' and 'causedBy', this function will
21
+ * update 'error' by chaining 'causedBy' to it.
22
+ * Specifically, 'causedBy''s message and stack will be appended
23
+ * to 'error''s message and stack, respectively, to simulate chained Errors.
24
+ *
25
+ * @param error the Error object to be updated
26
+ * @param causedBy an Error object that represents the cause of 'error'
27
+ * @returns 'error' after updating its message and stack fields
28
+ */
29
+ function chainError(error, causedBy) {
30
+ error.message += " ".concat(causedBy.toString());
31
+ if (causedBy.stack) {
32
+ error.stack += "\nCaused by: ".concat(causedBy.stack);
33
+ }
34
+ return error;
35
+ }
36
+ exports.chainError = chainError;
@@ -13,11 +13,11 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
16
+ import { InternalAxiosRequestConfig, AxiosResponse } from 'axios';
17
17
  import { CookieJar } from 'tough-cookie';
18
18
  export declare class CookieInterceptor {
19
19
  private readonly cookieJar;
20
20
  constructor(cookieJar: CookieJar | boolean);
21
- requestInterceptor(config: AxiosRequestConfig): Promise<AxiosRequestConfig<any>>;
21
+ requestInterceptor(config: InternalAxiosRequestConfig): Promise<InternalAxiosRequestConfig<any>>;
22
22
  responseInterceptor(response: AxiosResponse): Promise<AxiosResponse<any, any>>;
23
23
  }
@@ -102,6 +102,7 @@ var helper_1 = require("./helper");
102
102
  var logger_1 = __importDefault(require("./logger"));
103
103
  var stream_to_promise_1 = require("./stream-to-promise");
104
104
  var cookie_support_1 = require("./cookie-support");
105
+ var chain_error_1 = require("./chain-error");
105
106
  var RequestWrapper = /** @class */ (function () {
106
107
  function RequestWrapper(axiosOptions) {
107
108
  var _this = this;
@@ -582,9 +583,9 @@ function ensureJSONResponseBodyIsObject(response) {
582
583
  dataAsObject = JSON.parse(response.data);
583
584
  }
584
585
  catch (e) {
585
- logger_1.default.error('Response body was supposed to have JSON content but JSON parsing failed.');
586
- logger_1.default.error("Malformed JSON string: ".concat(response.data));
587
- throw e;
586
+ logger_1.default.verbose('Response body was supposed to have JSON content but JSON parsing failed.');
587
+ logger_1.default.verbose("Malformed JSON string: ".concat(response.data));
588
+ throw (0, chain_error_1.chainError)(new Error('Error processing HTTP response:'), e);
588
589
  }
589
590
  return dataAsObject;
590
591
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ibm-cloud-sdk-core",
3
- "version": "4.0.5",
3
+ "version": "4.0.6",
4
4
  "description": "Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.",
5
5
  "main": "index.js",
6
6
  "typings": "./es/index.d.ts",
@@ -42,7 +42,7 @@
42
42
  "@types/isstream": "^0.1.0",
43
43
  "@types/node": "~10.14.19",
44
44
  "@types/tough-cookie": "^4.0.0",
45
- "axios": "1.2.1",
45
+ "axios": "1.4.0",
46
46
  "camelcase": "^5.3.1",
47
47
  "debug": "^4.1.1",
48
48
  "dotenv": "^6.2.0",