Skip to content

Commit bf52e3b

Browse files
committed
context.sendFullErrors
1 parent b3828e4 commit bf52e3b

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

src/service/endpoint-context.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const Debug = require('debug')
22

33
class EndpointContext {
4-
constructor({party, endpoint, req, res, input, debug=Debug}){
4+
constructor({party, endpoint, req, res, input, debug=Debug, sendFullErrors=false}){
55
this.party = party
66
this.endpoint = endpoint
77
this.MiddlewareConfig = endpoint.info.MiddlewareConfig
@@ -22,6 +22,8 @@ class EndpointContext {
2222

2323
this.output = null
2424
this.outputError = null
25+
26+
this.sendFullErrors = sendFullErrors
2527

2628
this._debug = debug('dataparty.context.undefined')
2729
this._debugContent = []
@@ -65,6 +67,10 @@ class EndpointContext {
6567
setActor(actor){ this.actor = actor }
6668
setInputSession(input_session_id){ this.input_session_id = input_session_id }
6769

70+
setSendFullErrors(value){
71+
this.sendFullErrors = value
72+
}
73+
6874
/*async applyMiddleware(){
6975
7076
}*/

src/service/endpoints/echo.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ module.exports = class EchoEndpoint extends IEndpoint {
3535
debug('echo')
3636
ctx.debug('ctx.input', ctx.input)
3737

38-
console.log('throwing');
39-
throw new Error('derp')
40-
4138
return ctx.input
4239
}
4340
}

src/service/service-runner.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class ServiceRunner {
106106
//! check basic structure {pre: Object, post: Object}
107107

108108
return await Joi.object().keys({
109-
pre: Joi.object(),
110-
post: Joi.object()
109+
pre: Joi.object().keys(null),
110+
post: Joi.object().keys(null)
111111
})
112112
.validateAsync(endpoint.info.MiddlewareConfig)
113113
}
@@ -146,7 +146,8 @@ class ServiceRunner {
146146
endpoint,
147147
party: this.party,
148148
input: event.request.body,
149-
debug: Debug
149+
debug: Debug,
150+
sendFullErrors: this.sendFullErrors
150151
})
151152

152153
debug('running', endpoint.info.Name)
@@ -175,8 +176,8 @@ class ServiceRunner {
175176
error: {
176177
code: err.code,
177178
message: err.message,
178-
stack: (!this.sendFullErrors ? null : err.stack),
179-
... (!this.sendFullErrors ? null : err)
179+
stack: (!context.sendFullErrors ? undefined : err.stack),
180+
... (!context.sendFullErrors ? null : err)
180181
}
181182
})
182183
}

0 commit comments

Comments
 (0)