@scout9/app 1.0.0-alpha.0.3.6 → 1.0.0-alpha.0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scout9/app",
3
- "version": "1.0.0-alpha.0.3.6",
3
+ "version": "1.0.0-alpha.0.3.7",
4
4
  "description": "Build and deploy your Scout9 app for SMS auto replies",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -72,7 +72,7 @@ const cache = new ServerCache();
72
72
  cache.reset();
73
73
 
74
74
 
75
- const handleError = (e, res = undefined, tag = undefined) => {
75
+ const handleError = (e, res = undefined, tag = undefined, body = undefined) => {
76
76
  let name = e?.name || 'Runtime Error';
77
77
  let message = e?.message || 'Unknown error';
78
78
  let code = typeof e?.code === 'number'
@@ -94,14 +94,22 @@ const handleError = (e, res = undefined, tag = undefined) => {
94
94
  message = response.body;
95
95
  }
96
96
  }
97
+ if (body) {
98
+ console.log(colors.grey(JSON.stringify(body, null, 2)));
99
+ }
97
100
  if (tag && typeof tag === 'string') {
98
101
  message = `${tag}: ${message}`;
99
102
  }
103
+ if (typeof e?.constructor?.name === 'string') {
104
+ message = `(${e?.constructor?.name}) ${message}`;
105
+ }
100
106
  console.log(colors.red(`${colors.bold(`${code} Error`)}: ${message}`));
101
107
  if ('stack' in e) {
102
- console.log(colors.grey(e.stack));
108
+ console.log('STACK:', colors.grey(e.stack));
109
+ }
110
+ if (body) {
111
+ console.log('INPUT:', colors.grey(JSON.stringify(body, null, 2)));
103
112
  }
104
- console.log(colors);
105
113
  if (res) {
106
114
  res.writeHead(code, {'Content-Type': 'application/json'});
107
115
  res.end(JSON.stringify({
@@ -216,13 +224,13 @@ app.post(dev ? '/dev/workflow' : '/', async (req, res) => {
216
224
  status: 'Invalid WorkflowEvent Input'
217
225
  });
218
226
  } else {
219
- handleError(error, res, 'Workflow Template Event Parse Error');
227
+ handleError(error, res, 'Workflow Template Event Parse Error', req.body.event);
220
228
  }
221
229
  return;
222
230
  }
223
231
 
224
232
  if (!workflowEvent) {
225
- handleError(new Error('No workflowEvent defined'), res);
233
+ handleError(new Error('No workflowEvent defined'), res, req.body.event, 'Workflow Template Event No Event');
226
234
  }
227
235
  let response;
228
236
  try {
@@ -235,7 +243,19 @@ app.post(dev ? '/dev/workflow' : '/', async (req, res) => {
235
243
  }
236
244
  })
237
245
  } catch (error) {
238
- handleError(error, res, 'Workflow Template Runtime Error');
246
+ if (error instanceof ZodError) {
247
+ handleZodError({
248
+ error,
249
+ name: 'Workflow Template Event Request Parse Error',
250
+ body: req.body.event,
251
+ bodyLabel: 'Provided WorkflowEvent',
252
+ code: 400,
253
+ res,
254
+ status: 'Invalid WorkflowEvent Input'
255
+ });
256
+ } else {
257
+ handleError(error, res, 'Workflow Template Runtime Error', workflowEvent);
258
+ }
239
259
  return;
240
260
  }
241
261
 
@@ -263,7 +283,7 @@ app.post(dev ? '/dev/workflow' : '/', async (req, res) => {
263
283
  status: 'Invalid WorkflowResponse Output'
264
284
  });
265
285
  } else {
266
- handleError(error, res, 'Workflow Template Runtime Parse Error');
286
+ handleError(error, res, 'Workflow Template Runtime Parse Error', response);
267
287
  }
268
288
  }
269
289
  });