Cannot delete property 'ctx' of MoleculerClientError
deman4ik opened this issue · comments
After throwing any error from action I get
{
"errors": [
{
"message": "Cannot delete property 'ctx' of MoleculerClientError: Invalid role",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"nodesList"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"TypeError: Cannot delete property 'ctx' of MoleculerClientError: Invalid role",
" at .../node_modules/moleculer-apollo-server/src/service.js:121:8"
]
}
}
}
],
"data": null,
"extensions": {}
}
Line 121 of service.js
is attempting to delete the ctx
property from the error object:
if (err && err.ctx) {
delete err.ctx; // Avoid circular JSON
}
The error seems to be thrown by the interpreter here, but a Google search hasn't turned up anything for me regarding an "Invalid role" message, so I'm not sure what's causing that.
Running the example posts service with the nullIfError
flag set to false emits the proper error and does not run into this TypeError
. In our environment we throw errors regularly and don't run into this.
Can you provide more information / code sample of what service looks like? What node version are you running?
"Invalid role" - is my custom error message.
I think this error appears with new version of moleculer.
Tried to install "moleculer": "^0.14.0-beta4" to "simple" example from this repo and throw error in "hello" handler and "Cannot delete property 'ctx'" error appears.
In 0.14 the err.ctx
is a not enumerable property, so no need to delete it because it won't cause problem when you print or serialize the err
. By the way it is a writable
property, so maybe we can change this line to err.ctx = null
instead of delete err.ctx
.