Skip to content

Commit

Permalink
debug: temporarily allow stack traces in production
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed May 20, 2021
1 parent 00fbb15 commit c54008b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
9 changes: 2 additions & 7 deletions src/api/middleware/error-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@ import {ApiError} from "../lib/api-error";
import {generateErrorHtml} from "../../util/html/generate-html";
import {pickAccept} from "../util/util";

interface ErrorMiddlewareOptions {
removeStackTrace: boolean;
}
interface ErrorMiddlewareOptions {}

export const errorMiddleware =
(options: Partial<ErrorMiddlewareOptions> = {}) =>
(_options: Partial<ErrorMiddlewareOptions> = {}) =>
async (ex: Error | ApiError, req: Request, res: Response, _: NextFunction): Promise<void> => {
const apiError = ApiError.ensureApiError(ex);
if (options.removeStackTrace) {
apiError.stack = undefined;
}

const contentType = pickAccept(req.header("accept"));

Expand Down
2 changes: 1 addition & 1 deletion src/api/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Server implements IServer {
await this.metricsService.configureErrorHandlers(app);

// Apply fall-through error middleware
app.use(errorMiddleware({removeStackTrace: this.config.production}));
app.use(errorMiddleware());
this.app = app;
}

Expand Down
2 changes: 1 addition & 1 deletion test/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test(`Generates an JSON-formatted welcome payload when a request is sent to '${c
}
});

test.only(`Sends metrics data when an unsupported User-Agent header is discovered, but still responds with OK`, async t => {
test(`Sends metrics data when an unsupported User-Agent header is discovered, but still responds with OK`, async t => {
const metricsService = container.get<IMetricsService>();
const result = await sendRequest({
path: `${constant.endpoint.polyfill}?features=intersection-observer`,
Expand Down

0 comments on commit c54008b

Please sign in to comment.