Skip to content

Commit e3a9615

Browse files
authored
Properly bubble headers when throwing a data result (#12845)
1 parent 5112743 commit e3a9615

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

.changeset/proud-stingrays-wink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
Properly bubble headers when throwing a `data()` result

packages/router/router.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5061,15 +5061,25 @@ async function convertDataStrategyResultToDataResult(
50615061
type: ResultType.error,
50625062
error: result.data,
50635063
statusCode: result.init?.status,
5064+
headers: result.init?.headers
5065+
? new Headers(result.init.headers)
5066+
: undefined,
50645067
};
50655068
}
50665069

50675070
// Convert thrown data() to ErrorResponse instances
5068-
result = new ErrorResponseImpl(
5069-
result.init?.status || 500,
5070-
undefined,
5071-
result.data
5072-
);
5071+
return {
5072+
type: ResultType.error,
5073+
error: new ErrorResponseImpl(
5074+
result.init?.status || 500,
5075+
undefined,
5076+
result.data
5077+
),
5078+
statusCode: isRouteErrorResponse(result) ? result.status : undefined,
5079+
headers: result.init?.headers
5080+
? new Headers(result.init.headers)
5081+
: undefined,
5082+
};
50735083
}
50745084
return {
50755085
type: ResultType.error,

0 commit comments

Comments
 (0)