Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexXanderGrib committed Mar 7, 2024
1 parent 6195243 commit 06be8cb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/client/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import { type AnyRouter } from '@trpc/server'
// @ts-expect-error: Nuxt auto-imports
import { useRequestHeaders } from '#imports'
import { type FetchEsque } from '@trpc/client/dist/internals/types'
import { type FetchError } from "ofetch";

function isFetchError(error: unknown): error is FetchError {
return error instanceof Error && error.name === 'FetchError';
}

function customFetch(input: RequestInfo | URL, init?: RequestInit & { method: 'GET' }) {
return globalThis.$fetch.raw(input.toString(), init)
.catch((e) => {
// @ts-expect-error: Missing `e.response` type
if (e instanceof Error && e.name === 'FetchError' && e.response) { return e.response }
if (isFetchError(e) && e.response) { return e.response }
throw e
})
.then(response => ({
Expand Down

0 comments on commit 06be8cb

Please sign in to comment.