@@ -14,6 +14,7 @@ import { parseCookies, parseHeaders } from "./util";
14
14
15
15
const SET_COOKIE_HEADER = "set-cookie" ;
16
16
const CANNOT_BE_USED = "This cannot be used in OpenNext" ;
17
+ const ERROR_CODES = [ 404 , 500 , 403 , 401 ] ;
17
18
18
19
// We only need to implement the methods that are used by next.js
19
20
export class OpenNextNodeResponse extends Transform implements ServerResponse {
@@ -375,15 +376,15 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
375
376
return this ;
376
377
}
377
378
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
379
380
// We need to fix that
380
381
private fixHeadersForError ( ) {
381
382
if ( process . env . OPEN_NEXT_DANGEROUSLY_SET_ERROR_HEADERS === "true" ) {
382
383
return ;
383
384
}
384
- // We only check for 404 and 500 errors
385
+ // We only check for 401, 403, 404 and 500 errors
385
386
// 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 ) ) {
387
388
// For some reason calling this.setHeader("Cache-Control", "no-cache, no-store, must-revalidate") does not work here
388
389
// The function is not even called, i'm probably missing something obvious
389
390
this . headers [ "cache-control" ] =
0 commit comments