Skip to content

Commit

Permalink
fix: remove undefined string from fullUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
fzn0x committed Jul 15, 2024
1 parent 245b282 commit f091f5d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion browser/hyperfetch-browser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion browser/hyperfetch-browser.min.js.map

Large diffs are not rendered by default.

23 changes: 22 additions & 1 deletion src/types/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,39 @@ export type RequestFunction = {
initOptions?: InitOptions & { throwOnError: true }
): Promise<Error | T>

<T>(
url: string,
options?: RequestOptions,
data?: { [key: string]: unknown },
initOptions?: InitOptions & { throwOnError: true }
): Promise<Error | T>

<T>(
url: string,
options?: RequestOptions & { initOptions: { throwOnError: false } },
data?: { [key: string]: unknown },
initOptions?: InitOptions & { throwOnError: false }
): Promise<[Error | null, T | null]>

<T>(
url: string,
options?: RequestOptions,
data?: { [key: string]: unknown },
initOptions?: InitOptions & { throwOnError: false }
): Promise<[Error | null, T | null]>

<T>(
url: string,
options?: RequestOptions & { initOptions?: { throwOnError?: boolean } },
data?: { [key: string]: unknown },
initOptions?: InitOptions
initOptions?: InitOptions & { throwOnError?: boolean }
): Promise<[Error | null, T | null]>

<T>(
url: string,
options?: RequestOptions,
data?: { [key: string]: unknown } | unknown,
initOptions?: InitOptions & { throwOnError?: boolean }
): Promise<[Error | null, T | null]>
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/create-http-method.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createHTTPMethod } from './create-http-method.js'
describe('createHTTPMethod', () => {
it('working', async () => {
const [error] = await createHTTPMethod('http://localhost', 'GET', {})
expect(error?.message).equals('fetch failed')
expect(error?.message).equals(undefined)

Check failure on line 6 in src/utils/create-http-method.test.ts

View workflow job for this annotation

GitHub Actions / Main

src/utils/create-http-method.test.ts > createHTTPMethod > working

AssertionError: expected 'fetch failed' to equal undefined - Expected: undefined + Received: "fetch failed" ❯ src/utils/create-http-method.test.ts:6:28
})

it('allows override global throwOnError', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/create-http-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const createHTTPMethod = (
options: RequestOptions = Object.create(null),
data: { [key: string]: unknown } = Object.create(null),
initOptions?: InitOptions
): Promise<[Error | null, unknown]> => {
) => {
if (options.initOptions) {
initOptions = options.initOptions
}
Expand Down
18 changes: 18 additions & 0 deletions src/utils/create-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ describe('createRequest', () => {
}
})

it('Supports response clone', async () => {
try {
const res = await createRequest(
'https://jsonplaceholder.typicode.com/todos/1',
{ initOptions: { throwOnError: true } },
{},
{
throwOnError: true,
}
)

console.log(res)
expect(res).to.be.an.instanceOf(Response)
} catch (err) {
console.log(err)
}
})

it('Bun supports proxy', async () => {
try {
await createRequest(
Expand Down
2 changes: 1 addition & 1 deletion src/utils/create-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const createRequest: RequestFunction = async (
...otherOptions
} = options

const fullUrl = `${baseUrl}${url}`
const fullUrl = `${baseUrl || ''}${url}`

const reqHeaders = new Headers(headers)

Expand Down

0 comments on commit f091f5d

Please sign in to comment.