From e20dcdaa7b217aeeac7d8adaaa09dc87b8873c15 Mon Sep 17 00:00:00 2001 From: wobsoriano Date: Tue, 6 Feb 2024 15:27:26 -0800 Subject: [PATCH] fix: fetch error types not being forwarded --- package.json | 3 +- playground/package.json | 1 + pnpm-lock.yaml | 243 ++++------------------------------------ src/client/links.ts | 3 +- 4 files changed, 23 insertions(+), 227 deletions(-) diff --git a/package.json b/package.json index bc3118a..8750bde 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ }, "dependencies": { "h3": "^1.9.0", - "ofetch": "^1.3.3", "ohash": "^1.1.3" }, "devDependencies": { @@ -86,4 +85,4 @@ "@trpc/server": "^10.44.1" } } -} \ No newline at end of file +} diff --git a/playground/package.json b/playground/package.json index c25845a..9339959 100644 --- a/playground/package.json +++ b/playground/package.json @@ -11,6 +11,7 @@ "dependencies": { "@trpc/client": "^10.44.1", "@trpc/server": "^10.44.1", + "ofetch": "^1.3.3", "superjson": "^2.1.0", "trpc-nuxt": "workspace:*", "zod": "^3.22.4" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d2685ac..09cf105 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,9 +16,6 @@ importers: h3: specifier: ^1.9.0 version: 1.9.0 - ofetch: - specifier: ^1.3.3 - version: 1.3.3 ohash: specifier: ^1.1.3 version: 1.1.3 @@ -68,6 +65,9 @@ importers: '@trpc/server': specifier: ^10.44.1 version: 10.44.1 + ofetch: + specifier: ^1.3.3 + version: 1.3.3 superjson: specifier: ^2.1.0 version: 2.1.0 @@ -1679,8 +1679,8 @@ packages: nuxt: 3.8.0 vite: '*' dependencies: - '@nuxt/kit': 3.8.2 - '@nuxt/schema': 3.8.2 + '@nuxt/kit': 3.8.2(rollup@3.29.4) + '@nuxt/schema': 3.8.2(rollup@3.29.4) execa: 7.2.0 nuxt: 3.8.0(@types/node@20.8.7)(eslint@8.52.0)(typescript@5.2.2)(vite@4.5.0) vite: 4.5.0(@types/node@20.8.7) @@ -1783,7 +1783,7 @@ packages: '@antfu/utils': 0.7.6 '@nuxt/devtools-kit': 1.0.4(nuxt@3.8.0)(vite@4.5.0) '@nuxt/devtools-wizard': 1.0.4 - '@nuxt/kit': 3.8.2 + '@nuxt/kit': 3.8.2(rollup@3.29.4) birpc: 0.2.14 consola: 3.2.3 destr: 2.0.2 @@ -1813,9 +1813,9 @@ packages: semver: 7.5.4 simple-git: 3.21.0 sirv: 2.0.3 - unimport: 3.6.0(rollup@4.6.0) + unimport: 3.6.0(rollup@3.29.4) vite: 4.5.0(@types/node@20.8.7) - vite-plugin-inspect: 0.7.42(@nuxt/kit@3.8.2)(vite@4.5.0) + vite-plugin-inspect: 0.7.42(@nuxt/kit@3.8.2)(rollup@3.29.4)(vite@4.5.0) vite-plugin-vue-inspector: 4.0.0(vite@4.5.0) which: 3.0.1 ws: 8.14.2 @@ -1883,33 +1883,6 @@ packages: - supports-color dev: true - /@nuxt/kit@3.8.0: - resolution: {integrity: sha512-oIthQxeMIVs4ESVP5FqLYn8tj0S1sLd+eYreh+dNYgnJ2pTi7+THR12ONBNHjk668jqEe7ErUJ8UlGwqBzgezg==} - engines: {node: ^14.18.0 || >=16.10.0} - dependencies: - '@nuxt/schema': 3.8.0(rollup@3.29.4) - c12: 1.5.1 - consola: 3.2.3 - defu: 6.1.3 - globby: 13.2.2 - hash-sum: 2.0.0 - ignore: 5.3.0 - jiti: 1.21.0 - knitwork: 1.0.0 - mlly: 1.4.2 - pathe: 1.1.1 - pkg-types: 1.0.3 - scule: 1.1.0 - semver: 7.5.4 - ufo: 1.3.2 - unctx: 2.3.1 - unimport: 3.6.0(rollup@4.6.0) - untyped: 1.4.0 - transitivePeerDependencies: - - rollup - - supports-color - dev: true - /@nuxt/kit@3.8.0(rollup@3.29.4): resolution: {integrity: sha512-oIthQxeMIVs4ESVP5FqLYn8tj0S1sLd+eYreh+dNYgnJ2pTi7+THR12ONBNHjk668jqEe7ErUJ8UlGwqBzgezg==} engines: {node: ^14.18.0 || >=16.10.0} @@ -1937,33 +1910,6 @@ packages: - supports-color dev: true - /@nuxt/kit@3.8.2: - resolution: {integrity: sha512-LrXCm8hAkw+zpX8teUSD/LqXRarlXjbRiYxDkaqw739JSHFReWzBFgJbojsJqL4h1XIEScDGGOWiEgO4QO1sMg==} - engines: {node: ^14.18.0 || >=16.10.0} - dependencies: - '@nuxt/schema': 3.8.2 - c12: 1.5.1 - consola: 3.2.3 - defu: 6.1.3 - globby: 14.0.0 - hash-sum: 2.0.0 - ignore: 5.3.0 - jiti: 1.21.0 - knitwork: 1.0.0 - mlly: 1.4.2 - pathe: 1.1.1 - pkg-types: 1.0.3 - scule: 1.1.0 - semver: 7.5.4 - ufo: 1.3.2 - unctx: 2.3.1 - unimport: 3.6.0(rollup@4.6.0) - untyped: 1.4.0 - transitivePeerDependencies: - - rollup - - supports-color - dev: true - /@nuxt/kit@3.8.2(rollup@3.29.4): resolution: {integrity: sha512-LrXCm8hAkw+zpX8teUSD/LqXRarlXjbRiYxDkaqw739JSHFReWzBFgJbojsJqL4h1XIEScDGGOWiEgO4QO1sMg==} engines: {node: ^14.18.0 || >=16.10.0} @@ -2030,26 +1976,6 @@ packages: - supports-color dev: true - /@nuxt/schema@3.8.2: - resolution: {integrity: sha512-AMpysQ/wHK2sOujLShqYdC4OSj/S3fFJGjhYXqA2g6dgmz+FNQWJRG/ie5sI9r2EX9Ela1wt0GN1jZR3wYNE8Q==} - engines: {node: ^14.18.0 || >=16.10.0} - dependencies: - '@nuxt/ui-templates': 1.3.1 - consola: 3.2.3 - defu: 6.1.3 - hookable: 5.5.3 - pathe: 1.1.1 - pkg-types: 1.0.3 - scule: 1.1.0 - std-env: 3.5.0 - ufo: 1.3.2 - unimport: 3.6.0(rollup@4.6.0) - untyped: 1.4.0 - transitivePeerDependencies: - - rollup - - supports-color - dev: true - /@nuxt/schema@3.8.2(rollup@3.29.4): resolution: {integrity: sha512-AMpysQ/wHK2sOujLShqYdC4OSj/S3fFJGjhYXqA2g6dgmz+FNQWJRG/ie5sI9r2EX9Ela1wt0GN1jZR3wYNE8Q==} engines: {node: ^14.18.0 || >=16.10.0} @@ -2070,32 +1996,6 @@ packages: - supports-color dev: true - /@nuxt/telemetry@2.5.2: - resolution: {integrity: sha512-kZ+rWq/5MZonMhp8KGFI5zMaR2VsiWpnlkOLJIuIX2WoJl0DkHvtxCtuFq2erAqMVruWLpKU+tgMC+1cno/QmA==} - hasBin: true - dependencies: - '@nuxt/kit': 3.8.2 - ci-info: 3.8.0 - consola: 3.2.3 - create-require: 1.1.1 - defu: 6.1.3 - destr: 2.0.2 - dotenv: 16.3.1 - git-url-parse: 13.1.0 - is-docker: 3.0.0 - jiti: 1.21.0 - mri: 1.2.0 - nanoid: 4.0.2 - ofetch: 1.3.3 - parse-git-config: 3.0.0 - pathe: 1.1.1 - rc9: 2.1.1 - std-env: 3.5.0 - transitivePeerDependencies: - - rollup - - supports-color - dev: true - /@nuxt/telemetry@2.5.2(rollup@3.29.4): resolution: {integrity: sha512-kZ+rWq/5MZonMhp8KGFI5zMaR2VsiWpnlkOLJIuIX2WoJl0DkHvtxCtuFq2erAqMVruWLpKU+tgMC+1cno/QmA==} hasBin: true @@ -2132,8 +2032,8 @@ packages: peerDependencies: vue: ^3.3.4 dependencies: - '@nuxt/kit': 3.8.0 - '@rollup/plugin-replace': 5.0.5(rollup@4.6.0) + '@nuxt/kit': 3.8.0(rollup@3.29.4) + '@rollup/plugin-replace': 5.0.5(rollup@3.29.4) '@vitejs/plugin-vue': 4.5.0(vite@4.5.0)(vue@3.3.9) '@vitejs/plugin-vue-jsx': 3.1.0(vite@4.5.0)(vue@3.3.9) autoprefixer: 10.4.16(postcss@8.4.31) @@ -3469,26 +3369,6 @@ packages: - rollup dev: true - /@vue-macros/common@1.8.0(vue@3.3.9): - resolution: {integrity: sha512-auDJJzE0z3uRe3867e0DsqcseKImktNf5ojCZgUKqiVxb2yTlwlgOVAYCgoep9oITqxkXQymSvFeKhedi8PhaA==} - engines: {node: '>=16.14.0'} - peerDependencies: - vue: ^2.7.0 || ^3.2.25 - peerDependenciesMeta: - vue: - optional: true - dependencies: - '@babel/types': 7.23.5 - '@rollup/pluginutils': 5.0.5(rollup@4.6.0) - '@vue/compiler-sfc': 3.3.9 - ast-kit: 0.11.2 - local-pkg: 0.4.3 - magic-string-ast: 0.3.0 - vue: 3.3.9(typescript@5.2.2) - transitivePeerDependencies: - - rollup - dev: true - /@vue/babel-helper-vue-transform-on@1.1.5: resolution: {integrity: sha512-SgUymFpMoAyWeYWLAY+MkCK3QEROsiUnfaw5zxOVD/M64KQs8D/4oK6Q5omVA2hnvEOE0SCkH2TZxs/jnnUj7w==} dev: true @@ -3999,17 +3879,6 @@ packages: util: 0.12.5 dev: true - /ast-kit@0.11.2: - resolution: {integrity: sha512-Q0DjXK4ApbVoIf9GLyCo252tUH44iTnD/hiJ2TQaJeydYWSpKk0sI34+WMel8S9Wt5pbLgG02oJ+gkgX5DV3sQ==} - engines: {node: '>=16.14.0'} - dependencies: - '@babel/parser': 7.23.5 - '@rollup/pluginutils': 5.0.5(rollup@4.6.0) - pathe: 1.1.1 - transitivePeerDependencies: - - rollup - dev: true - /ast-kit@0.11.2(rollup@3.29.4): resolution: {integrity: sha512-Q0DjXK4ApbVoIf9GLyCo252tUH44iTnD/hiJ2TQaJeydYWSpKk0sI34+WMel8S9Wt5pbLgG02oJ+gkgX5DV3sQ==} engines: {node: '>=16.14.0'} @@ -4021,17 +3890,6 @@ packages: - rollup dev: true - /ast-kit@0.9.5: - resolution: {integrity: sha512-kbL7ERlqjXubdDd+szuwdlQ1xUxEz9mCz1+m07ftNVStgwRb2RWw+U6oKo08PAvOishMxiqz1mlJyLl8yQx2Qg==} - engines: {node: '>=16.14.0'} - dependencies: - '@babel/parser': 7.23.5 - '@rollup/pluginutils': 5.0.5(rollup@4.6.0) - pathe: 1.1.1 - transitivePeerDependencies: - - rollup - dev: true - /ast-kit@0.9.5(rollup@3.29.4): resolution: {integrity: sha512-kbL7ERlqjXubdDd+szuwdlQ1xUxEz9mCz1+m07ftNVStgwRb2RWw+U6oKo08PAvOishMxiqz1mlJyLl8yQx2Qg==} engines: {node: '>=16.14.0'} @@ -4050,16 +3908,6 @@ packages: tslib: 2.6.2 dev: true - /ast-walker-scope@0.5.0: - resolution: {integrity: sha512-NsyHMxBh4dmdEHjBo1/TBZvCKxffmZxRYhmclfu0PP6Aftre47jOHYaYaNqJcV0bxihxFXhDkzLHUwHc0ocd0Q==} - engines: {node: '>=16.14.0'} - dependencies: - '@babel/parser': 7.23.5 - ast-kit: 0.9.5 - transitivePeerDependencies: - - rollup - dev: true - /ast-walker-scope@0.5.0(rollup@3.29.4): resolution: {integrity: sha512-NsyHMxBh4dmdEHjBo1/TBZvCKxffmZxRYhmclfu0PP6Aftre47jOHYaYaNqJcV0bxihxFXhDkzLHUwHc0ocd0Q==} engines: {node: '>=16.14.0'} @@ -4893,6 +4741,7 @@ packages: /destr@2.0.1: resolution: {integrity: sha512-M1Ob1zPSIvlARiJUkKqvAZ3VAqQY6Jcuth/pBKQ2b1dX/Qx0OnJ8Vux6J2H5PTMQeRzWrrbTu70VxBfv/OPDJA==} + dev: true /destr@2.0.2: resolution: {integrity: sha512-65AlobnZMiCET00KaFFjUefxDX0khFA/E4myqZ7a6Sq1yZtR8+FVIvilVX66vF2uobSumxooYZChiRPCKNqhmg==} @@ -6651,7 +6500,7 @@ packages: mlly: 1.4.2 node-forge: 1.3.1 pathe: 1.1.1 - ufo: 1.3.0 + ufo: 1.3.2 untun: 0.1.2 uqr: 0.1.2 dev: true @@ -7883,7 +7732,6 @@ packages: /node-fetch-native@1.4.1: resolution: {integrity: sha512-NsXBU0UgBxo2rQLOeWNZqS3fvflWePMECr8CoSWoSTqCqGbVVsvl9vZu1HfQicYN0g5piV9Gh8RTEvo/uP752w==} - dev: true /node-fetch@2.7.0: resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} @@ -8135,9 +7983,9 @@ packages: dependencies: '@nuxt/devalue': 2.0.2 '@nuxt/devtools': 1.0.4(nuxt@3.8.0)(vite@4.5.0) - '@nuxt/kit': 3.8.0 + '@nuxt/kit': 3.8.0(rollup@3.29.4) '@nuxt/schema': 3.8.0(rollup@3.29.4) - '@nuxt/telemetry': 2.5.2 + '@nuxt/telemetry': 2.5.2(rollup@3.29.4) '@nuxt/ui-templates': 1.3.1 '@nuxt/vite-builder': 3.8.0(@types/node@20.8.7)(eslint@8.52.0)(typescript@5.2.2)(vue@3.3.9) '@types/node': 20.8.7 @@ -8181,9 +8029,9 @@ packages: uncrypto: 0.1.3 unctx: 2.3.1 unenv: 1.8.0 - unimport: 3.6.0(rollup@4.6.0) + unimport: 3.6.0(rollup@3.29.4) unplugin: 1.5.1 - unplugin-vue-router: 0.7.0(vue-router@4.2.5)(vue@3.3.9) + unplugin-vue-router: 0.7.0(rollup@3.29.4)(vue-router@4.2.5)(vue@3.3.9) untyped: 1.4.0 vue: 3.3.9(typescript@5.2.2) vue-bundle-renderer: 2.0.0 @@ -8373,9 +8221,9 @@ packages: /ofetch@1.3.3: resolution: {integrity: sha512-s1ZCMmQWXy4b5K/TW9i/DtiN8Ku+xCiHcjQ6/J/nDdssirrQNOoB165Zu8EqLMA2lln1JUth9a0aW9Ap2ctrUg==} dependencies: - destr: 2.0.1 - node-fetch-native: 1.4.0 - ufo: 1.3.0 + destr: 2.0.2 + node-fetch-native: 1.4.1 + ufo: 1.3.2 /ohash@1.1.3: resolution: {integrity: sha512-zuHHiGTYTA1sYJ/wZN+t5HKZaH23i4yI1HMwbuXm24Nid7Dv0KcuRlKoNKS9UNfAVSBlnGLcuQrnOKWOZoEGaw==} @@ -10266,6 +10114,7 @@ packages: /ufo@1.3.0: resolution: {integrity: sha512-bRn3CsoojyNStCZe0BG0Mt4Nr/4KF+rhFlnNXybgqt5pXHNFRlqinSoQaTrGyzE4X8aHplSb+TorH+COin9Yxw==} + dev: true /ufo@1.3.1: resolution: {integrity: sha512-uY/99gMLIOlJPwATcMVYfqDSxUR9//AUcgZMzwfSTJPDKzA1S8mX4VLqa+fiAtveraQUBCz4FFcwVZBGbwBXIw==} @@ -10613,33 +10462,6 @@ packages: - vue dev: true - /unplugin-vue-router@0.7.0(vue-router@4.2.5)(vue@3.3.9): - resolution: {integrity: sha512-ddRreGq0t5vlSB7OMy4e4cfU1w2AwBQCwmvW3oP/0IHQiokzbx4hd3TpwBu3eIAFVuhX2cwNQwp1U32UybTVCw==} - peerDependencies: - vue-router: ^4.1.0 - peerDependenciesMeta: - vue-router: - optional: true - dependencies: - '@babel/types': 7.23.5 - '@rollup/pluginutils': 5.0.5(rollup@4.6.0) - '@vue-macros/common': 1.8.0(vue@3.3.9) - ast-walker-scope: 0.5.0 - chokidar: 3.5.3 - fast-glob: 3.3.2 - json5: 2.2.3 - local-pkg: 0.4.3 - mlly: 1.4.2 - pathe: 1.1.1 - scule: 1.1.0 - unplugin: 1.5.1 - vue-router: 4.2.5(vue@3.3.9) - yaml: 2.3.2 - transitivePeerDependencies: - - rollup - - vue - dev: true - /unplugin@1.4.0: resolution: {integrity: sha512-5x4eIEL6WgbzqGtF9UV8VEC/ehKptPXDS6L2b0mv4FRMkJxRtjaJfOWDd6a8+kYbqsjklix7yWP0N3SUepjXcg==} dependencies: @@ -11026,31 +10848,6 @@ packages: - supports-color dev: true - /vite-plugin-inspect@0.7.42(@nuxt/kit@3.8.2)(vite@4.5.0): - resolution: {integrity: sha512-JCyX86wr3siQc+p9Kd0t8VkFHAJag0RaQVIpdFGSv5FEaePEVB6+V/RGtz2dQkkGSXQzRWrPs4cU3dRKg32bXw==} - engines: {node: '>=14'} - peerDependencies: - '@nuxt/kit': '*' - vite: ^3.1.0 || ^4.0.0 || ^5.0.0-0 - peerDependenciesMeta: - '@nuxt/kit': - optional: true - dependencies: - '@antfu/utils': 0.7.6 - '@nuxt/kit': 3.8.2 - '@rollup/pluginutils': 5.0.5(rollup@4.6.0) - debug: 4.3.4 - error-stack-parser-es: 0.1.1 - fs-extra: 11.2.0 - open: 9.1.0 - picocolors: 1.0.0 - sirv: 2.0.3 - vite: 4.5.0(@types/node@20.8.7) - transitivePeerDependencies: - - rollup - - supports-color - dev: true - /vite-plugin-vue-inspector@4.0.0(vite@4.5.0): resolution: {integrity: sha512-xNjMbRj3YrebuuInTvlC8ghPtzT+3LjMIQPeeR/5CaFd+WcbA9wBnECZmlcP3GITCVED0SxGmTyoJ3iVKsK4vQ==} peerDependencies: diff --git a/src/client/links.ts b/src/client/links.ts index b982d6b..61f1004 100644 --- a/src/client/links.ts +++ b/src/client/links.ts @@ -5,7 +5,6 @@ import { type HTTPBatchLinkOptions as _HTTPBatchLinkOptions } from '@trpc/client' import { type AnyRouter } from '@trpc/server' -import { FetchError } from 'ofetch' // @ts-expect-error: Nuxt auto-imports import { useRequestHeaders } from '#imports' import { type FetchEsque } from '@trpc/client/dist/internals/types' @@ -13,7 +12,7 @@ import { type FetchEsque } from '@trpc/client/dist/internals/types' function customFetch(input: RequestInfo | URL, init?: RequestInit & { method: 'GET' }) { return globalThis.$fetch.raw(input.toString(), init) .catch((e) => { - if (e instanceof FetchError && e.response) { return e.response } + if (e.constructor.name === 'FetchError' && e.response) { return e.response } throw e }) .then(response => ({