Skip to content

Commit 5c6c5f8

Browse files
authored
fix: restore error bubbling behavior from v1.0.0 (#1048)
- Replace FetchConfigurationError throwing with Promise-based error bubbling - Add cookie handling to .then() chain for successful responses only - Preserve v1.0.0 behavior where HTTP errors reach caller unchanged - Fix authentication error handling regression from v1.0.1 Allows .catch((error) => error.data) pattern to work correctly again for normal HTTP error responses like 401 authentication failures.
1 parent 882c0cb commit 5c6c5f8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/runtime/utils/fetch.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ export async function _fetch<T>(
4848

4949
try {
5050
// Adapted from https://nuxt.com/docs/getting-started/data-fetching#pass-cookies-from-server-side-api-calls-on-ssr-response
51-
const res = await $fetch.raw(joinedPath, fetchOptions)
52-
53-
if (import.meta.server && proxyCookies && event) {
54-
const cookies = res.headers.getSetCookie()
55-
event.node.res.appendHeader('set-cookie', cookies)
56-
}
51+
return $fetch.raw(joinedPath, fetchOptions).then((res) => {
52+
if (import.meta.server && proxyCookies && event) {
53+
const cookies = res.headers.getSetCookie()
54+
event.node.res.appendHeader('set-cookie', cookies)
55+
}
5756

58-
return res._data as T
57+
return res._data as T
58+
})
5959
}
6060
catch (error) {
6161
let errorMessage = `${ERROR_PREFIX} Error while requesting ${joinedPath}.`

0 commit comments

Comments
 (0)