mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-23 08:20:37 +01:00
add custom fetch function for node 18
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { CreateTRPCClientOptions, TRPCClientErrorLike, inferRouterProxyClient } from '@trpc/client'
|
||||
import { createTRPCProxyClient } from '@trpc/client'
|
||||
import { FetchError } from 'ohmyfetch'
|
||||
import type {
|
||||
AnyMutationProcedure,
|
||||
AnyProcedure,
|
||||
@@ -111,3 +112,17 @@ export function createTRPCNuxtProxyClient<TRouter extends AnyRouter>(opts: Creat
|
||||
|
||||
return decoratedClient
|
||||
}
|
||||
|
||||
export function customFetch(input: RequestInfo | URL, options?: RequestInit) {
|
||||
return globalThis.$fetch.raw(input.toString(), options)
|
||||
.catch((e) => {
|
||||
if (e instanceof FetchError && e.response)
|
||||
return e.response
|
||||
|
||||
throw e
|
||||
})
|
||||
.then(response => ({
|
||||
...response,
|
||||
json: () => Promise.resolve(response._data),
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user