q-koa 12.2.4 → 12.2.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/core/app.js +18 -3
- package/core/middlewares.js +1 -1
- package/package.json +1 -1
package/core/app.js
CHANGED
|
@@ -10,6 +10,7 @@ const moment = require('moment')
|
|
|
10
10
|
const { EventEmitter } = require('events')
|
|
11
11
|
const nodeVm = require('vm')
|
|
12
12
|
const LRU = require('lru-cache')
|
|
13
|
+
const axios = require('axios')
|
|
13
14
|
|
|
14
15
|
const { Serve } = require('static-koa-router')
|
|
15
16
|
|
|
@@ -247,13 +248,14 @@ class APP {
|
|
|
247
248
|
content: err.stack,
|
|
248
249
|
header: ctx.request.header,
|
|
249
250
|
}
|
|
251
|
+
|
|
250
252
|
if (
|
|
251
253
|
this.app &&
|
|
252
254
|
this.app[appName] &&
|
|
253
255
|
this.app[appName].model &&
|
|
254
256
|
this.app[appName].model.log
|
|
255
257
|
) {
|
|
256
|
-
this.app[appName].model.log.
|
|
258
|
+
this.app[appName].model.log.create(errorData)
|
|
257
259
|
}
|
|
258
260
|
if (is_dev) {
|
|
259
261
|
console.log(err.stack)
|
|
@@ -623,7 +625,11 @@ class APP {
|
|
|
623
625
|
'indexList',
|
|
624
626
|
[]
|
|
625
627
|
)
|
|
626
|
-
|
|
628
|
+
const log_push_url = _.get(
|
|
629
|
+
this.app[appName],
|
|
630
|
+
'appConfig.log_push_url',
|
|
631
|
+
[]
|
|
632
|
+
)
|
|
627
633
|
const instance = this.app[appName].sequelize.define(
|
|
628
634
|
folder,
|
|
629
635
|
attributes,
|
|
@@ -640,6 +646,15 @@ class APP {
|
|
|
640
646
|
hooks: {
|
|
641
647
|
beforeCreate: (res, t) => {
|
|
642
648
|
try {
|
|
649
|
+
if (folder === 'log' && log_push_url) {
|
|
650
|
+
axios
|
|
651
|
+
.get(
|
|
652
|
+
`${log_push_url}/${appName}/${encodeURIComponent(
|
|
653
|
+
res.toJSON().message
|
|
654
|
+
)}`
|
|
655
|
+
)
|
|
656
|
+
.then((res) => res.data)
|
|
657
|
+
}
|
|
643
658
|
if (res.toJSON().user_id) {
|
|
644
659
|
res.createdid = res.toJSON().user_id
|
|
645
660
|
}
|
|
@@ -1956,7 +1971,7 @@ class APP {
|
|
|
1956
1971
|
app[appName].model &&
|
|
1957
1972
|
app[appName].model.log
|
|
1958
1973
|
) {
|
|
1959
|
-
app[appName].model.log.
|
|
1974
|
+
app[appName].model.log.create(errorData)
|
|
1960
1975
|
}
|
|
1961
1976
|
})
|
|
1962
1977
|
}
|
package/core/middlewares.js
CHANGED
|
@@ -32,7 +32,7 @@ exports.miErrors = () => async (ctx, next) => {
|
|
|
32
32
|
}
|
|
33
33
|
if (app && app.model && app.model.log) {
|
|
34
34
|
if (!['service'].includes(e.type)) {
|
|
35
|
-
app.model.log.
|
|
35
|
+
app.model.log.create(errorData)
|
|
36
36
|
if (e.type === 'transaction') {
|
|
37
37
|
return ctx.ERROR('发生错误了')
|
|
38
38
|
}
|