Skip to content

Commit

Permalink
fix: don't show full stacktrace when missing token
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrovs committed Feb 21, 2021
1 parent d23ff6f commit 96c869d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
10 changes: 9 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ enum ActionTypes { HOST = 'host', JOIN = 'join' }
app.post('/', (req, res, next) => { ActionTypes.HOST == req.query.action ? next() : next('route') }, apiController.initHost);
app.post('/', (req, res, next) => { ActionTypes.JOIN == req.query.action ? next() : next('route') }, apiController.initClient);
app.post('/', protect, apiController.sendMessage);
// flushHeaders should be false to allow rejecting the connection after inspecting request (status 400)
app.get('/', protect, sse(/* options */ { flushHeaders: false }), apiController.listen);
// flushHeaders should be false to allow rejecting the connection after inspecting request (status 400)
// disable 401 error stacktrace logging as it is expected due to missing credentials
app.use(function (err: any, req: any, res: any, next: any) {
if (err && err.status == 401) {
res.sendStatus(401);
} else {
next(err);
}
});

export default app;
10 changes: 0 additions & 10 deletions test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ import { assert } from "chai";
import app from "../src/app";
import { HostConfiguration } from "../src/models/HostConfiguration";

// disable 401 error stacktrace logging as it is
// expected due to missing credentials test
app.use(function (err: any, req: any, res: any, next: any) {
if (err && err.status == 401) {
res.sendStatus(401);
} else {
next(err);
}
});

describe("GET /random-url", () => {
it("should return 404", (done) => {
request(app).get("/reset")
Expand Down

0 comments on commit 96c869d

Please sign in to comment.