@pitcher/js-api 1.21.0-beta.6 → 1.21.0-beta.7

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/js-api.esm.js CHANGED
@@ -2998,6 +2998,29 @@ const onlineRestApiHandlers = {
2998
2998
  }
2999
2999
  };
3000
3000
 
3001
+ const TRUNCATE_LENGTH_TRIGGER = 10;
3002
+ function truncateObject(obj, depth = 1) {
3003
+ if (depth === 0 || typeof obj !== "object" || obj === null) {
3004
+ return obj;
3005
+ }
3006
+ if (Array.isArray(obj)) {
3007
+ if (obj.length > TRUNCATE_LENGTH_TRIGGER) {
3008
+ return `[Truncated - ${obj.length} length array]`;
3009
+ }
3010
+ return obj.map((item) => truncateObject(item, depth - 1));
3011
+ }
3012
+ const keys = Object.keys(obj);
3013
+ if (keys.length > TRUNCATE_LENGTH_TRIGGER) {
3014
+ return `{Truncated - ${keys.length} properties obj}`;
3015
+ }
3016
+ return keys.reduce(
3017
+ (acc, key) => {
3018
+ acc[key] = truncateObject(obj[key], depth - 1);
3019
+ return acc;
3020
+ },
3021
+ {}
3022
+ );
3023
+ }
3001
3024
  function updateOnlineHandlersEnv(env) {
3002
3025
  env && setEnv(env);
3003
3026
  }
@@ -3052,10 +3075,22 @@ class LowLevelApi extends EventEmitter {
3052
3075
  );
3053
3076
  if (type === "get_env") updateOnlineHandlersEnv(res.response.body);
3054
3077
  } else if (res.response.status === "error") {
3055
- this.options.errorLogger?.({
3056
- message: `Pitcher JS API call failure: ${res.request.type}`,
3057
- js_api_response: JSON.stringify(res)
3058
- });
3078
+ if (this.options.errorLogger) {
3079
+ this.options.errorLogger({
3080
+ message: `Pitcher JS API call failure: ${res.request.type}`,
3081
+ js_api_response: JSON.stringify({
3082
+ ...res,
3083
+ response: {
3084
+ ...res.response,
3085
+ body: truncateObject(res.response.body)
3086
+ },
3087
+ request: {
3088
+ ...res.request,
3089
+ body: truncateObject(res.request.body)
3090
+ }
3091
+ })
3092
+ });
3093
+ }
3059
3094
  reject(this.options.casing === "camel" ? camelCaseKeys(res.response.body) : res.response.body);
3060
3095
  } else {
3061
3096
  throw new Error("unsupported response status");