diff --git a/README.md b/README.md index 24d1c04..6d44958 100644 --- a/README.md +++ b/README.md @@ -606,7 +606,7 @@ wretch().middlewares([ until: (response, error) => response && response.ok, onRetry: null, retryOnNetworkError: false, - resolveWithLatestReponse: false + resolveWithLatestResponse: false }) ])./* ... */ diff --git a/src/middlewares/retry.ts b/src/middlewares/retry.ts index 24b800b..1df0a76 100644 --- a/src/middlewares/retry.ts +++ b/src/middlewares/retry.ts @@ -53,7 +53,7 @@ export type RetryOptions = { * * _Default: `false`_ */ - resolveWithLatestReponse?: boolean + resolveWithLatestResponse?: boolean } /** @@ -74,7 +74,7 @@ export type RetryOptions = { * until: (response, error) => response && response.ok, * onRetry: null, * retryOnNetworkError: false, - * resolveWithLatestReponse: false + * resolveWithLatestResponse: false * }) * ]) * @@ -105,7 +105,7 @@ export const retry: RetryMiddleware = ({ until = defaultUntil, onRetry = null, retryOnNetworkError = false, - resolveWithLatestReponse = false + resolveWithLatestResponse = false } = {}) => { return next => (url, opts) => { @@ -141,11 +141,11 @@ export const retry: RetryMiddleware = ({ return checkStatus(null, error) }) } else { - return resolveWithLatestReponse ? response : Promise.reject(error || new Error("Number of attempts exceeded.")) + return resolveWithLatestResponse ? response : Promise.reject(error || new Error("Number of attempts exceeded.")) } } - return resolveWithLatestReponse ? response : error ? Promise.reject(error) : response + return resolveWithLatestResponse ? response : error ? Promise.reject(error) : response }) } diff --git a/test/node/middlewares/retry.spec.ts b/test/node/middlewares/retry.spec.ts index b2d9ba7..1ff37e0 100644 --- a/test/node/middlewares/retry.spec.ts +++ b/test/node/middlewares/retry.spec.ts @@ -111,8 +111,8 @@ export default describe("Retry Middleware", () => { expect(counter).toBe(10) }) - it("should pass the latest response instead of throwing an error if resolveWithLatestReponse is true", async () => { - const w = base().middlewares([retry({ delayTimer: 1, resolveWithLatestReponse: true })], true) + it("should pass the latest response instead of throwing an error if resolveWithLatestResponse is true", async () => { + const w = base().middlewares([retry({ delayTimer: 1, resolveWithLatestResponse: true })], true) // WretchError await expect(w.get("/retry").res()).rejects.toMatchObject({ response: { ok: false, counter: 12 } }) })