@jcbuisson/express-x 1.6.11 → 1.6.13

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": "@jcbuisson/express-x",
3
- "version": "1.6.11",
3
+ "version": "1.6.13",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
package/src/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
 
2
- import { expressX } from './server.mjs'
2
+ import { expressX, MyCustomError } from './server.mjs'
3
3
  import { hashPassword, protect, isAuthenticated, isNotExpired } from './common-hooks.mjs'
4
4
  import { getContextConnection, resetConnection, getConnectionDataItem, setConnectionDataItem, removeConnectionDataItem, sendServiceEventToClient } from './context.mjs'
5
5
 
6
6
  export {
7
- expressX,
7
+ expressX, MyCustomError,
8
8
 
9
9
  getContextConnection,
10
10
  resetConnection,
package/src/server.mjs CHANGED
@@ -3,6 +3,14 @@ import http from 'http'
3
3
  import { Server } from "socket.io"
4
4
  import express from 'express'
5
5
 
6
+ export class MyCustomError extends Error {
7
+ constructor(message, code) {
8
+ super(message);
9
+ this.name = 'MyCustomError'
10
+ this.code = code
11
+ }
12
+ }
13
+
6
14
  /*
7
15
  * Enhance `app` express application with services and real-time features
8
16
  */
@@ -401,27 +409,29 @@ export function expressX(prisma, options = {}) {
401
409
  })
402
410
  } catch(err) {
403
411
  app.log('error', err.toString())
412
+ app.log('verbose', err.stack)
404
413
  socket.emit('client-response', {
405
414
  uid,
406
- error: err.toString(),
415
+ error: new MyCustomError(err.message, err.code),
407
416
  })
408
417
  }
409
418
  } else {
410
419
  socket.emit('client-response', {
411
420
  uid,
412
- error: `there is no method named '${action}' for service '${name}'`,
421
+ error: new MyCustomError(`there is no method named '${action}' for service '${name}'`, missing-method),
413
422
  })
414
423
  }
415
424
  } catch(error) {
425
+ app.log('verbose', error.stack)
416
426
  socket.emit('client-response', {
417
427
  uid,
418
- error,
419
- })
428
+ error: new MyCustomError("unknown error", 'unknown-error'),
429
+ })
420
430
  }
421
431
  } else {
422
432
  socket.emit('client-response', {
423
433
  uid,
424
- error: `there is no service named '${name}'`,
434
+ error: new MyCustomError(`there is no service named '${name}'`, 'missing-service'),
425
435
  })
426
436
  }
427
437
  })