get whole stack in case of api exception
Massimo Melina committed
Feb 7, 2022 at 12:39 UTC
16622ddabd14e779d267cdbde483f9f476712767
1 file changed
+4
-11
src/apis.ts
+4
-11
@@ -45,17 +45,10 @@ export function apiMiddleware(apis: ApiHandlers) : Koa.Middleware {
45
ctx.body = 'invalid api'
46
return ctx.status = 404
47
}
48
- let res
49
- try {
50
- const csrf = ctx.cookies.get('csrf')
51
- if (csrf && csrf !== params.csrf) // we don't rely on SameSite cookie option because it's https-only
52
- res = new ApiError(401, 'csrf')
53
- else
54
- res = await apis[ctx.path](params || {}, ctx)
55
- }
56
- catch(e) {
57
- ctx.throw(500, String(e))
58
- }
48
+ const csrf = ctx.cookies.get('csrf')
49
+ // we don't rely on SameSite cookie option because it's https-only
50
+ const res = csrf && csrf !== params.csrf ? new ApiError(401, 'csrf')
51
+ : await apis[ctx.path](params || {}, ctx)
52
if (res && res instanceof EventEmitter) {
53
const sse = createSSE(ctx)
54
res.on('data', data => sse.send(data))