From 7e1b54d1363ba3f5fe57fe8089babab921a8e9ea Mon Sep 17 00:00:00 2001 From: Oliver Vorasai Date: Wed, 10 Nov 2021 05:00:12 -0700 Subject: [PATCH] fix: remove baseurl append on retry (#25) --- src/fetch.ts | 4 ++-- test/index.test.mjs | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/fetch.ts b/src/fetch.ts index cdf6502..f09830c 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -1,5 +1,5 @@ import destr from 'destr' -import { joinURL, withQuery } from 'ufo' +import { withBase, withQuery } from 'ufo' import type { Fetch, RequestInfo, RequestInit, Response } from './types' import { createFetchError } from './error' @@ -68,7 +68,7 @@ export function createFetch ({ fetch }: CreateFetchOptions): $Fetch { const $fetchRaw: $Fetch['raw'] = async function $fetchRaw (request, opts = {}) { if (typeof request === 'string') { if (opts.baseURL) { - request = joinURL(opts.baseURL, request) + request = withBase(request, opts.baseURL) } if (opts.params) { request = withQuery(request, opts.params) diff --git a/test/index.test.mjs b/test/index.test.mjs index c744271..99bdee3 100644 --- a/test/index.test.mjs +++ b/test/index.test.mjs @@ -61,4 +61,9 @@ describe('ohmyfetch', () => { expect(err.response?.data).to.deep.eq(err.data) expect(err.request).to.equal(getURL('404')) }) + + it('baseURL with retry', async () => { + const err = await $fetch('', { baseURL: getURL('404'), retry: 3 }).catch(err => err) + expect(err.request).to.equal(getURL('404')) + }) })