bajo 0.2.25 → 0.2.26
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/boot/helper/error.js +11 -3
- package/boot/lib/print.js +2 -2
- package/package.json +1 -1
package/boot/helper/error.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { last, isPlainObject, each, isArray, get } from 'lodash-es'
|
|
1
|
+
import { last, isPlainObject, each, isArray, get, isEmpty, merge } from 'lodash-es'
|
|
2
2
|
import getPluginName from './get-plugin-name.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -18,6 +18,7 @@ Error.stackTraceLimit = 15
|
|
|
18
18
|
|
|
19
19
|
function formatErrorDetails (value, ns) {
|
|
20
20
|
const { print } = this.bajo.helper
|
|
21
|
+
const result = {}
|
|
21
22
|
each(value, (v, i) => {
|
|
22
23
|
if (!v.context) {
|
|
23
24
|
v.error = print.__(v.error, { ns })
|
|
@@ -25,11 +26,15 @@ function formatErrorDetails (value, ns) {
|
|
|
25
26
|
}
|
|
26
27
|
v.context.message = v.message
|
|
27
28
|
if (v.type === 'any.only') v.context.ref = print.__(`field.${get(v, 'context.valids.0.key')}`, { ns })
|
|
29
|
+
const field = get(v, 'context.key')
|
|
30
|
+
const val = get(v, 'context.value')
|
|
28
31
|
value[i] = {
|
|
29
|
-
field
|
|
32
|
+
field,
|
|
30
33
|
error: print.__(`validation.${v.type}`, v.context, { ns })
|
|
31
34
|
}
|
|
35
|
+
result[field] = val
|
|
32
36
|
})
|
|
37
|
+
return result
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
function error (msg = 'Internal server error', ...args) {
|
|
@@ -55,13 +60,16 @@ function error (msg = 'Internal server error', ...args) {
|
|
|
55
60
|
if (isPlainObject(payload)) {
|
|
56
61
|
delete payload.class
|
|
57
62
|
delete payload.ns
|
|
63
|
+
const values = {}
|
|
58
64
|
for (const key in payload) {
|
|
59
65
|
const value = payload[key]
|
|
60
66
|
if (key === 'details' && isArray(value) && orgMsg === 'Validation Error') {
|
|
61
|
-
formatErrorDetails.call(this, value, ns)
|
|
67
|
+
const result = formatErrorDetails.call(this, value, ns)
|
|
68
|
+
if (result) merge(values, result)
|
|
62
69
|
}
|
|
63
70
|
err[key] = value
|
|
64
71
|
}
|
|
72
|
+
if (!isEmpty(values)) err.values = values
|
|
65
73
|
}
|
|
66
74
|
return err
|
|
67
75
|
}
|
package/boot/lib/print.js
CHANGED
|
@@ -31,12 +31,12 @@ export class Print {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
setText (text, ...args) {
|
|
34
|
-
|
|
34
|
+
const { dayjs } = this.scope.bajo.helper
|
|
35
35
|
text = this.__(text, ...args)
|
|
36
36
|
this.setOpts(args)
|
|
37
37
|
const prefixes = []
|
|
38
38
|
const texts = []
|
|
39
|
-
|
|
39
|
+
if (this.opts.showDatetime) prefixes.push('[' + dayjs().toISOString() + ']')
|
|
40
40
|
if (this.opts.showCounter) texts.push('[' + this.getElapsed() + ']')
|
|
41
41
|
if (prefixes.length > 0) this.ora.prefixText = this.ora.prefixText + prefixes.join(' ')
|
|
42
42
|
if (texts.length > 0) text = texts.join(' ') + ' ' + text
|