@jcbuisson/express-x 1.0.19 → 1.0.20

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/package.json +1 -1
  2. package/src/index.mjs +38 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
package/src/index.mjs CHANGED
@@ -156,32 +156,57 @@ function expressX(app, options={}) {
156
156
 
157
157
  app.post(path, async (req, res) => {
158
158
  context.http.req = req
159
- const value = await service.__create(context, req.body)
160
- res.json(value)
159
+ try {
160
+ const value = await service.__create(context, req.body)
161
+ res.json(value)
162
+ } catch(err) {
163
+ console.log('callErr', err)
164
+ res.status(500).send(err.toString())
165
+ }
161
166
  })
162
167
 
163
168
  app.get(path, async (req, res) => {
164
169
  context.http.req = req
165
- const values = await service.__find(context, req.body)
166
- res.json(values)
170
+ try {
171
+ const values = await service.__find(context, req.body)
172
+ res.json(values)
173
+ } catch(err) {
174
+ console.log('callErr', err)
175
+ res.status(500).send(err.toString())
176
+ }
167
177
  })
168
178
 
169
179
  app.get(`${path}/:id`, async (req, res) => {
170
180
  context.http.req = req
171
- const value = await service.__get(context, parseInt(req.params.id))
172
- res.json(value)
181
+ try {
182
+ const value = await service.__get(context, parseInt(req.params.id))
183
+ res.json(value)
184
+ } catch(err) {
185
+ console.log('callErr', err)
186
+ res.status(500).send(err.toString())
187
+ }
173
188
  })
174
189
 
175
190
  app.patch(`${path}/:id`, async (req, res) => {
176
191
  context.http.req = req
177
- const value = await service.__patch(context, parseInt(req.params.id), req.body)
178
- res.json(value)
192
+ try {
193
+ const value = await service.__patch(context, parseInt(req.params.id), req.body)
194
+ res.json(value)
195
+ } catch(err) {
196
+ console.log('callErr', err)
197
+ res.status(500).send(err.toString())
198
+ }
179
199
  })
180
200
 
181
201
  app.delete(`${path}/:id`, async (req, res) => {
182
202
  context.http.req = req
183
- const value = await service.__remove(context, parseInt(req.params.id))
184
- res.json(value)
203
+ try {
204
+ const value = await service.__remove(context, parseInt(req.params.id))
205
+ res.json(value)
206
+ } catch(err) {
207
+ console.log('callErr', err)
208
+ res.status(500).send(err.toString())
209
+ }
185
210
  })
186
211
 
187
212
  if (options.debug) console.log(`added HTTP endpoints for service '${service.name}' at path '${path}'`)
@@ -261,11 +286,11 @@ function expressX(app, options={}) {
261
286
  }
262
287
  }
263
288
  }
264
- } catch(callErr) {
265
- console.log('callErr', callErr)
289
+ } catch(err) {
290
+ console.log('callErr', err)
266
291
  io.emit('client-response', {
267
292
  uid,
268
- error: callErr.toString(),
293
+ error: err.toString(),
269
294
  })
270
295
  }
271
296
  } else {