Skip to content

Commit a404448

Browse files
committed
add 403 and 401 to fixHeadersForError
1 parent 7f45c90 commit a404448

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/open-next/src/http/openNextResponse.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { parseCookies, parseHeaders } from "./util";
1414

1515
const SET_COOKIE_HEADER = "set-cookie";
1616
const CANNOT_BE_USED = "This cannot be used in OpenNext";
17+
const ERROR_CODES = [404, 500, 403, 401];
1718

1819
// We only need to implement the methods that are used by next.js
1920
export class OpenNextNodeResponse extends Transform implements ServerResponse {
@@ -375,15 +376,15 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
375376
return this;
376377
}
377378

378-
// For some reason, next returns the 500 error page with some cache-control headers
379+
// For some reason, next returns the error pages with some cache-control headers
379380
// We need to fix that
380381
private fixHeadersForError() {
381382
if (process.env.OPEN_NEXT_DANGEROUSLY_SET_ERROR_HEADERS === "true") {
382383
return;
383384
}
384-
// We only check for 404 and 500 errors
385+
// We only check for 401, 403, 404 and 500 errors
385386
// The rest should be errors that are handled by the user and they should set the cache headers themselves
386-
if (this.statusCode === 404 || this.statusCode === 500) {
387+
if (ERROR_CODES.includes(this.statusCode)) {
387388
// For some reason calling this.setHeader("Cache-Control", "no-cache, no-store, must-revalidate") does not work here
388389
// The function is not even called, i'm probably missing something obvious
389390
this.headers["cache-control"] =

0 commit comments

Comments
 (0)