ti2-tourplan 1.0.10 → 1.0.11

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 +15 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -26,6 +26,13 @@ const getHeaders = ({ length, requestId }) => ({
26
26
  ...requestId ? { requestId } : {},
27
27
  });
28
28
 
29
+ const axiosSafeRequest = R.pick(['headers', 'method', 'url', 'data']);
30
+ const axiosSafeResponse = response => {
31
+ const retVal = R.pick(['data', 'status', 'statusText', 'headers', 'request'], response);
32
+ retVal.request = axiosSafeRequest(retVal.request);
33
+ return retVal;
34
+ };
35
+
29
36
  class Plugin {
30
37
  constructor(params = {}) { // we get the env variables from here
31
38
  Object.entries(params).forEach(([attr, value]) => {
@@ -33,19 +40,23 @@ class Plugin {
33
40
  });
34
41
  if (this.events) {
35
42
  axiosRaw.interceptors.request.use(request => {
36
- this.events.emit(`${this.name}.axios.request`, JSON.parse(JSON.stringify(request)));
43
+ this.events.emit(`${this.name}.axios.request`, axiosSafeRequest(request));
37
44
  return request;
38
45
  });
39
46
  axiosRaw.interceptors.response.use(response => {
40
- this.events.emit(`${this.name}.axios.response`, JSON.parse(JSON.stringify(response)));
47
+ this.events.emit(`${this.name}.axios.response`, axiosSafeResponse(response));
41
48
  return response;
42
49
  });
43
50
  }
44
51
  const pluginObj = this;
45
52
  this.axios = async (...args) => axiosRaw(...args).catch(err => {
46
- console.log('error in ti2-tourplan', err);
53
+ const errMsg = R.omit(['config'], err.toJSON());
54
+ console.log(`error in ${this.name}`, args[0], errMsg);
47
55
  if (pluginObj.events) {
48
- pluginObj.events.emit(`${this.name}.axios.error`, { request: args[0], err });
56
+ pluginObj.events.emit(`${this.name}.axios.error`, {
57
+ request: args[0],
58
+ err: errMsg,
59
+ });
49
60
  }
50
61
  throw err;
51
62
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-tourplan",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Tourplan's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {