undici-retry
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -5,5 +5,5 @@ export { ResponseError } from './lib/ResponseError'; | ||
export { createDelayToNextMinuteResolver } from './lib/delayResolvers'; | ||
export { isInternalRequestError, isRequestResult } from './lib/typeGuards'; | ||
export { isInternalRequestError, isRequestResult, isResponseError, isRequestInternalError } from './lib/typeGuards'; | ||
export type { CreateDelayToNextMinuteResolverConfig } from './lib/delayResolvers'; | ||
export type { RetryConfig, RequestResult, DelayResolver, RequestParams, RequestInternalError } from './lib/undiciRetry'; | ||
export type { Either } from './lib/either'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isRequestResult = exports.isInternalRequestError = exports.createDelayToNextMinuteResolver = exports.DEFAULT_RETRY_CONFIG = exports.sendWithRetry = exports.InternalRequestError = exports.ResponseError = void 0; | ||
exports.isRequestInternalError = exports.isResponseError = exports.isRequestResult = exports.isInternalRequestError = exports.createDelayToNextMinuteResolver = exports.DEFAULT_RETRY_CONFIG = exports.sendWithRetry = exports.InternalRequestError = exports.ResponseError = void 0; | ||
var ResponseError_1 = require("./lib/ResponseError"); | ||
@@ -16,2 +16,4 @@ Object.defineProperty(exports, "ResponseError", { enumerable: true, get: function () { return ResponseError_1.ResponseError; } }); | ||
Object.defineProperty(exports, "isRequestResult", { enumerable: true, get: function () { return typeGuards_1.isRequestResult; } }); | ||
Object.defineProperty(exports, "isResponseError", { enumerable: true, get: function () { return typeGuards_1.isResponseError; } }); | ||
Object.defineProperty(exports, "isRequestInternalError", { enumerable: true, get: function () { return typeGuards_1.isRequestInternalError; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,2 @@ | ||
import { ErrorDetails } from './commonTypes'; | ||
export type RequestErrorParams = { | ||
@@ -7,6 +8,6 @@ message: string; | ||
export declare class InternalRequestError extends Error { | ||
readonly details?: ErrorDetails; | ||
readonly error: Error; | ||
readonly requestLabel?: string; | ||
readonly isInternalRequestError = true; | ||
constructor(params: RequestErrorParams); | ||
} |
@@ -5,4 +5,4 @@ "use strict"; | ||
class InternalRequestError extends Error { | ||
details; | ||
error; | ||
requestLabel; | ||
isInternalRequestError = true; | ||
@@ -12,4 +12,6 @@ constructor(params) { | ||
this.name = 'InternalRequestError'; | ||
this.details = { | ||
requestLabel: params.requestLabel, | ||
}; | ||
this.error = params.error; | ||
this.requestLabel = params.requestLabel; | ||
} | ||
@@ -16,0 +18,0 @@ } |
@@ -1,2 +0,2 @@ | ||
export type ErrorDetails = Record<string, unknown>; | ||
import { ErrorDetails } from './commonTypes'; | ||
export type RequestErrorParams = { | ||
@@ -6,2 +6,3 @@ message: string; | ||
details?: ErrorDetails; | ||
requestLabel?: string; | ||
}; | ||
@@ -8,0 +9,0 @@ export declare class ResponseError extends Error { |
@@ -11,3 +11,6 @@ "use strict"; | ||
this.name = 'ResponseError'; | ||
this.details = params.details; | ||
this.details = { | ||
...params.details, | ||
requestLabel: params.requestLabel, | ||
}; | ||
this.errorCode = params.errorCode; | ||
@@ -14,0 +17,0 @@ } |
import { RequestInternalError, RequestResult } from './undiciRetry'; | ||
export declare function isInternalRequestError(entity: unknown): entity is RequestInternalError; | ||
import { ResponseError } from './ResponseError'; | ||
import { InternalRequestError } from './InternalRequestError'; | ||
export declare function isRequestInternalError(entity: unknown): entity is RequestInternalError; | ||
export declare function isInternalRequestError(entity: unknown): entity is InternalRequestError; | ||
export declare function isRequestResult(entity: unknown): entity is RequestResult<unknown>; | ||
export declare function isResponseError(entity: unknown): entity is ResponseError; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isRequestResult = exports.isInternalRequestError = void 0; | ||
exports.isResponseError = exports.isRequestResult = exports.isInternalRequestError = exports.isRequestInternalError = void 0; | ||
function isRequestInternalError(entity) { | ||
return 'error' in entity && 'requestLabel' in entity; | ||
} | ||
exports.isRequestInternalError = isRequestInternalError; | ||
function isInternalRequestError(entity) { | ||
return 'error' in entity; | ||
return 'isInternalRequestError' in entity; | ||
} | ||
@@ -12,2 +16,6 @@ exports.isInternalRequestError = isInternalRequestError; | ||
exports.isRequestResult = isRequestResult; | ||
function isResponseError(entity) { | ||
return 'isResponseError' in entity; | ||
} | ||
exports.isResponseError = isResponseError; | ||
//# sourceMappingURL=typeGuards.js.map |
@@ -5,2 +5,3 @@ import type { Dispatcher } from 'undici'; | ||
export type RequestResult<T> = { | ||
error?: never; | ||
body: T; | ||
@@ -14,2 +15,5 @@ headers: IncomingHttpHeaders; | ||
requestLabel?: string; | ||
body?: never; | ||
headers?: never; | ||
statusCode?: never; | ||
}; | ||
@@ -16,0 +20,0 @@ export type DelayResolver = (response: Dispatcher.ResponseData) => number | undefined; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const InternalRequestError_1 = require("./InternalRequestError"); | ||
const typeGuards_1 = require("./typeGuards"); | ||
const TIMEOUT_ERRORS = [undici_1.errors.BodyTimeoutError.name, undici_1.errors.HeadersTimeoutError.name]; | ||
@@ -28,3 +29,3 @@ exports.DEFAULT_RETRY_CONFIG = { | ||
if (response.statusCode < 400) { | ||
const resolvedBody = await resolveBody(response, requestParams.blobBody, requestParams.safeParseJson); | ||
const resolvedBody = await resolveBody(response, requestParams.requestLabel, requestParams.blobBody, requestParams.safeParseJson); | ||
return { | ||
@@ -41,3 +42,3 @@ result: { | ||
attemptsSoFar >= retryConfig.maxAttempts) { | ||
const resolvedBody = await resolveBody(response); | ||
const resolvedBody = await resolveBody(response, requestParams.requestLabel); | ||
return { | ||
@@ -57,3 +58,3 @@ error: { | ||
if (delay === -1) { | ||
const resolvedBody = await resolveBody(response); | ||
const resolvedBody = await resolveBody(response, requestParams.requestLabel); | ||
return { | ||
@@ -93,2 +94,5 @@ error: { | ||
else { | ||
if ((0, typeGuards_1.isResponseError)(err)) { | ||
throw err; | ||
} | ||
throw new InternalRequestError_1.InternalRequestError({ | ||
@@ -105,3 +109,3 @@ error: err, | ||
exports.sendWithRetry = sendWithRetry; | ||
async function resolveBody(response, blobBody = false, safeParseJson = false) { | ||
async function resolveBody(response, requestLabel = 'N/A', blobBody = false, safeParseJson = false) { | ||
if (blobBody) { | ||
@@ -124,2 +128,3 @@ return await response.body.blob(); | ||
errorCode: 'INVALID_HTTP_RESPONSE_JSON', | ||
requestLabel, | ||
details: { | ||
@@ -126,0 +131,0 @@ rawBody, |
{ | ||
"name": "undici-retry", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Library for handling retry logic with undici HTTP client", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25308
27
320