ti2-ventrata 1.0.22 → 1.0.23

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.
Files changed (2) hide show
  1. package/index.js +13 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -34,6 +34,13 @@ const getHeaders = ({
34
34
  // 'Octo-Capabilities': 'octo/pricing',
35
35
  });
36
36
 
37
+ const axiosSafeRequest = R.pick(['headers', 'method', 'url', 'data']);
38
+ const axiosSafeResponse = response => {
39
+ const retVal = R.pick(['data', 'status', 'statusText', 'headers', 'request'], response);
40
+ retVal.request = axiosSafeRequest(retVal.request);
41
+ return retVal;
42
+ };
43
+
37
44
  class Plugin {
38
45
  constructor(params) { // we get the env variables from here
39
46
  Object.entries(params).forEach(([attr, value]) => {
@@ -41,27 +48,25 @@ class Plugin {
41
48
  });
42
49
  if (this.events) {
43
50
  axiosRaw.interceptors.request.use(request => {
44
- this.events.emit(`${this.name}.axios.request`, JSON.parse(JSON.stringify(request)));
51
+ this.events.emit(`${this.name}.axios.request`, axiosSafeRequest(request));
45
52
  return request;
46
53
  });
47
54
  axiosRaw.interceptors.response.use(response => {
48
- this.events.emit(`${this.name}.axios.response`, JSON.parse(JSON.stringify(response)));
55
+ this.events.emit(`${this.name}.axios.response`, axiosSafeResponse(response));
49
56
  return response;
50
57
  });
51
58
  }
52
59
  const pluginObj = this;
53
60
  this.axios = async (...args) => axiosRaw(...args).catch(err => {
54
- const errMsg = R.path(['response', 'data', 'errorMessage'], err);
55
- console.log(`error in ${this.name}`, args[0], errMsg || err);
61
+ const errMsg = R.omit(['config'], err.toJSON());
62
+ console.log(`error in ${this.name}`, args[0], errMsg);
56
63
  if (pluginObj.events) {
57
64
  pluginObj.events.emit(`${this.name}.axios.error`, {
58
65
  request: args[0],
59
- err: JSON.parse(JSON.stringify(err)),
60
- errMsg,
66
+ err: errMsg,
61
67
  });
62
68
  }
63
- if (errMsg) throw new Error(errMsg);
64
- throw err;
69
+ throw R.pathOr(err, ['response', 'data', 'errorMessage'], err);
65
70
  });
66
71
 
67
72
  this.tokenTemplate = () => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-ventrata",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "Ventrata's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {