waibu-db 2.11.0 → 2.12.0

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/lib/util.js CHANGED
@@ -1,3 +1,5 @@
1
+ export const actions = ['countRecord', 'createAggregate', 'createHistogram', 'createRecord', 'findAllRecord', 'findOneRecord', 'findRecord', 'getRecord', 'removeRecord', 'updateRecord']
2
+
1
3
  export async function prepCrud ({ model, body, id, req, reply, transaction, options = {}, args } = {}) {
2
4
  const { isSet } = this.app.lib.aneka
3
5
  const { importModule } = this.app.bajo
@@ -9,6 +11,9 @@ export async function prepCrud ({ model, body, id, req, reply, transaction, opti
9
11
 
10
12
  const cfgWeb = this.app.waibu.getConfig()
11
13
  const opts = cloneDeep(omit(options, ['trx']))
14
+ if (opts.suppressError === true) opts.suppressError = actions
15
+ else if (isString(opts.suppressError)) opts.suppressError = [opts.suppressError]
16
+ else opts.suppressError = opts.suppressError ?? []
12
17
  opts.trx = options.trx
13
18
  const params = this.getParams(req, ...args)
14
19
  for (const k of ['count', 'fields']) {
@@ -65,7 +70,8 @@ export async function getOneRecord (model, id, filter, options) {
65
70
  }
66
71
 
67
72
  export async function processHandler ({ action, model, handler, options } = {}) {
68
- function suppressedReturn () {
73
+ function suppressedReturn (err) {
74
+ this.log.error(err)
69
75
  if (action === 'countRecord') return options.dataOnly ? 0 : { data: 0, warnings: [options.req.t('supppressedError')] }
70
76
  if (['createRecord', 'getRecord'].includes(action)) return options.dataOnly ? {} : { data: {}, warnings: [options.req.t('supppressedError')] }
71
77
  if (action === 'removeRecord') return options.dataOnly ? {} : { oldData: {}, warnings: [options.req.t('supppressedError')] }
@@ -76,7 +82,7 @@ export async function processHandler ({ action, model, handler, options } = {})
76
82
  try {
77
83
  return options.trx === true ? (await model.transaction(handler)) : (await handler())
78
84
  } catch (err) {
79
- if (options.suppressError) return suppressedReturn()
85
+ if (options.suppressError.includes(action)) return suppressedReturn.call(this, err)
80
86
  throw err
81
87
  }
82
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-db",
3
- "version": "2.11.0",
3
+ "version": "2.12.0",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -3,6 +3,8 @@
3
3
  ## 2026-03-26
4
4
 
5
5
  - [2.11.0] Adding ```suppressError``` to model options
6
+ - [2.12.0] ```suppressError``` can now be either one or more actions. If set to ```true```, it assumed to be all actions
7
+ - [2.12.0] Print error log even in ```suppressError```
6
8
 
7
9
  ## 2026-03-25
8
10