Skip to content

Commit b3828e4

Browse files
committed
configurable debug reply
1 parent 7cb628d commit b3828e4

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

src/service/endpoints/echo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = class EchoEndpoint extends IEndpoint {
2424
},
2525
post: {
2626
/*encrypt: false,*/
27-
/*validate: Joi.object().keys(null).description('any input allowed'),*/
27+
validate: Joi.object().keys(null).description('any output allowed')
2828
}
2929
}
3030
}

src/service/service-runner.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ const EndpointRunner = require('./endpoint-runner')
1111
const Router = require('origin-router').Router
1212

1313
class ServiceRunner {
14-
constructor({service, party}){
14+
constructor({service, party, sendFullErrors=false}){
1515
this.party = party
1616
this.service = service
17+
this.sendFullErrors = sendFullErrors
1718

1819
this.middleware = { pre: {}, post: {} }
1920
this.endpoint = {}
@@ -152,17 +153,33 @@ class ServiceRunner {
152153

153154
const middlewareCfg = Hoek.reach(endpoint, 'info.MiddlewareConfig')
154155

155-
await this.runMiddleware(middlewareCfg, context, 'pre')
156-
157-
const result = await endpoint.run(context)
156+
try{
158157

159-
context.setOutput(result)
158+
await this.runMiddleware(middlewareCfg, context, 'pre')
159+
160+
const result = await endpoint.run(context)
161+
162+
context.setOutput(result)
163+
164+
await this.runMiddleware(middlewareCfg, context, 'post')
165+
166+
debug('result', result)
160167

161-
await this.runMiddleware(middlewareCfg, context, 'post')
168+
context.res.send(result)
162169

163-
debug('result', result)
170+
}
171+
catch(err){
172+
debug('caught error', err)
164173

165-
context.res.send(result)
174+
context.res.status(500).send({
175+
error: {
176+
code: err.code,
177+
message: err.message,
178+
stack: (!this.sendFullErrors ? null : err.stack),
179+
... (!this.sendFullErrors ? null : err)
180+
}
181+
})
182+
}
166183

167184
}
168185
}

0 commit comments

Comments
 (0)