Skip to content

Commit 6ddef08

Browse files
committed
Fix async hook error message
1 parent d4b5bbb commit 6ddef08

File tree

4 files changed

+39
-40
lines changed

4 files changed

+39
-40
lines changed

package-lock.json

+24-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
"devDependencies": {
2626
"chai": "^4.3.7",
2727
"coveralls": "^3.1.1",
28-
"eslint": "^8.37.0",
28+
"eslint": "^8.38.0",
2929
"eslint-config-google": "^0.14.0",
3030
"glob": "^9.3.4",
3131
"mocha": "^10.2.0",
32-
"mssql-cr-layer": "^2.0.17",
32+
"mssql-cr-layer": "^2.0.18",
3333
"nyc": "^15.1.0",
34-
"pg-cr-layer": "^2.0.20",
34+
"pg-cr-layer": "^2.0.21",
3535
"unorm": "^1.6.0",
3636
"validator": "^13.9.0"
3737
},
@@ -45,6 +45,6 @@
4545
"@ayk/co": "^4.6.4",
4646
"json-schema-table": "^1.0.25",
4747
"lodash": "^4.17.21",
48-
"sql-view": "^1.0.15"
48+
"sql-view": "^1.0.16"
4949
}
5050
}

src/adapters/common.js

-12
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ exports.create = function (record, data, options) {
7171
}
7272
return record
7373
})
74-
.catch(err => {
75-
console.error(insertCommand, err)
76-
throw err
77-
})
7874
}
7975

8076
exports.update = function (record, data, options) {
@@ -173,10 +169,6 @@ exports.update = function (record, data, options) {
173169
}
174170
return record
175171
})
176-
.catch(err => {
177-
console.error(updateCommand, err)
178-
throw err
179-
})
180172
}
181173

182174
exports.destroy = function (data, options) {
@@ -223,10 +215,6 @@ exports.destroy = function (data, options) {
223215
)
224216
return recordset.length
225217
})
226-
.catch(err => {
227-
console.error(deleteCommand, err)
228-
throw err
229-
})
230218
}
231219

232220
function checkRecordsetLength(data, key, n, type) {

src/index.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const {
1111
getUpdatedAtColumnName
1212
} = require('./adapters/common')
1313

14+
const getErrorMessage = err => (err.precedingErrors || []).join(' ') + err.message
15+
1416
const isGenerator = obj =>
1517
typeof obj.next === 'function' && typeof obj.throw === 'function'
1618

@@ -842,12 +844,19 @@ function runHooks(hooks, model, options, data, validatedInstance) {
842844
throw new EntityError({
843845
type: hook.name + 'HookError',
844846
message: err.message,
845-
errors: [{path: hook.id, message: err.message}],
847+
errors: [{path: hook.id, message: getErrorMessage(err)}],
846848
err
847849
})
848850
}
849851
if (res && res.then) {
850-
return res
852+
return res.catch(err => {
853+
throw new EntityError({
854+
type: hook.name + 'HookError',
855+
message: err.message,
856+
errors: [{path: hook.id, message: getErrorMessage(err)}],
857+
err
858+
})
859+
})
851860
}
852861
})
853862
},

0 commit comments

Comments
 (0)