@jcbuisson/express-x 2.1.4 → 2.1.5

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": "2.1.4",
3
+ "version": "2.1.5",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
@@ -34,6 +34,14 @@ export function protect(field) {
34
34
  }
35
35
  }
36
36
 
37
+
38
+ class NotAuthenticatedError extends Error {
39
+ constructor(message) {
40
+ super(message)
41
+ this.code = 'not-authenticated'
42
+ }
43
+ }
44
+
37
45
  /*
38
46
  * Throw an error for a client service method call when socket.data.expiresAt is missing or overdue
39
47
  */
@@ -47,10 +55,10 @@ export const isNotExpired = async (context) => {
47
55
  if (now > expiresAtDate) {
48
56
  // expiration date is met: clear socket.data & throw exception
49
57
  context.socket.data = {}
50
- throw new Error('session-expired')
58
+ throw new NotAuthenticatedError("Session expired")
51
59
  }
52
60
  } else {
53
- throw new Error('session-expired')
61
+ throw new NotAuthenticatedError("no expiresAt in socket.data")
54
62
  }
55
63
  }
56
64
 
@@ -60,5 +68,5 @@ export const isNotExpired = async (context) => {
60
68
  export const isAuthenticated = async (context) => {
61
69
  // do nothing if it's not a client call from a ws connexion
62
70
  if (!context.socket) return
63
- if (!context.socket.data.user) throw new Error('not-authenticated')
71
+ if (!context.socket.data.user) throw new NotAuthenticatedError('no user in socket.data')
64
72
  }
package/src/server.mjs CHANGED
@@ -115,7 +115,7 @@ export function expressX(config) {
115
115
  result,
116
116
  })
117
117
  } catch(err) {
118
- console.log('!!!!!!error', err)
118
+ console.log('!!!!!!error', err.code, err.message)
119
119
  app.log('verbose', err.stack)
120
120
  socket.emit('client-response', {
121
121
  uid,