Skip to content

Commit 6ac7be8

Browse files
committed
fix: Include set.headers on response when an error is thrown
1 parent 5e00476 commit 6ac7be8

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/internal/compile-fetch-function.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { MatchedRoute } from "rou3";
2+
import { HttpError, NotFoundHttpError } from "../errors";
3+
import { HttpStatus } from "../status";
24
import type { LifeCycleHooks, RouterData, ServerSideFetch } from "../types";
5+
import { Context } from "./context";
36
import {
47
cleanupCompiledWhitespace,
58
getRawPathname,
69
serializeErrorResponse,
710
} from "./utils";
8-
import { Context } from "./context";
9-
import { HttpError, NotFoundHttpError } from "../errors";
10-
import { HttpStatus } from "../status";
1111

1212
export function compileFetchFunction(options: CompileOptions): ServerSideFetch {
1313
const onGlobalRequestCount = options.hooks.onGlobalRequest?.length;
@@ -144,7 +144,12 @@ function compileErrorResponse(tabs: number): string {
144144
${indent} error instanceof utils.HttpError
145145
${indent} ? error.status
146146
${indent} : utils.HttpStatus.InternalServerError;
147-
${indent}return (ctx.response = Response.json(utils.serializeErrorResponse(error), { status }));`;
147+
${indent}return (
148+
${indent} ctx.response = Response.json(
149+
${indent} utils.serializeErrorResponse(error),
150+
${indent} { status, headers: ctx.set.headers },
151+
${indent} )
152+
${indent});`;
148153
}
149154

150155
type CompileOptions = {

0 commit comments

Comments
 (0)