Skip to content

Commit

Permalink
feat: expose createHTTPMethod and createHTTPError
Browse files Browse the repository at this point in the history
  • Loading branch information
fzn0x committed Jul 15, 2024
1 parent 8ce438f commit cc6a113
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 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.

4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { HttpRequestFunctions } from './types/request.js'

import { getAbortController } from './utils/get-abort-controller.js'
import { createHTTPMethod } from './utils/create-http-method.js'
import { createHTTPError } from './utils/create-http-error.js'

/**
* Initializes the HTTP request functions with a base URL and options.
Expand Down Expand Up @@ -36,6 +37,9 @@ export function init(
patch: (url, options, data) => createHTTPMethod(url, 'PATCH', options, data, initOptions),
head: (url, options, data) => createHTTPMethod(url, 'HEAD', options, data, initOptions),
options: (url, options, data) => createHTTPMethod(url, 'OPTIONS', options, data, initOptions),

createHTTPMethod,
createHTTPError,
getAbortController,
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/types/request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { InitOptions } from './init.js'
import type { createHTTPMethod } from '../utils/create-http-method.js'
import type { createHTTPError } from '../utils/create-http-error.js'

export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS'

Expand Down Expand Up @@ -69,5 +71,7 @@ export interface HttpRequestFunctions {
head: HttpRequestFunction
options: HttpRequestFunction

createHTTPMethod: typeof createHTTPMethod
createHTTPError: typeof createHTTPError
getAbortController(): AbortController | null
}
2 changes: 1 addition & 1 deletion src/utils/create-http-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface HTTPError extends Error {
* @param {Request} request - The Request object used to make the fetch request.
* @param {string} code - The error code to use for the error object.
*
* @returns {Error} An Error object with additional properties for response and data.
* @returns {Error} An Error object with additional properties for response, request, and code.
*/
export function createHTTPError(response: Response, request?: Request, code?: string): Error {
try {
Expand Down

0 comments on commit cc6a113

Please sign in to comment.