Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e97ee16

Browse files
committed
fix(ai): properly handle error data on streams
1 parent 6055688 commit e97ee16

File tree

1 file changed

+6
-1
lines changed
  • src/runtime/ai/server/utils

1 file changed

+6
-1
lines changed

src/runtime/ai/server/utils/ai.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,14 @@ async function handleProxyError(err: H3Error) {
111111
if (import.meta.dev && err.statusCode === 403) {
112112
console.warn('It seems that your Cloudflare API token does not have the `Worker AI` permission.\nOpen `https://dash.cloudflare.com/profile/api-tokens` and edit your NuxtHub token.\nAdd the `Account > Worker AI > Read` permission to your token and save it.')
113113
}
114+
let data = err.data || {}
115+
if (typeof (err as any).response?.json === 'function') {
116+
data = (await (err as any).response.json())?.data || {}
117+
}
114118
throw createError({
115119
statusCode: err.statusCode,
116120
// @ts-expect-error not aware of data property
117-
message: err.data?.message || err.message
121+
message: err.data?.message || err.message,
122+
data
118123
})
119124
}

0 commit comments

Comments
 (0)