import { DownloadError , isCommonNetworkError } from "./error" ; import { ValidationError } from "./validator" ; /**
 * The handler that decide whether
 */ export interface RetryHandler { retry ( url , attempt , error ) : boolean | Promise < boolean > ; retry ( url , attempt , error ) : boolean | Promise < boolean > ; param url param attempt param error The error object thrown during this download. It can be  DownloadError or $ ValidationError .
     *  returns retry ( url , attempt , error ) : boolean | Promise < boolean > ; } export interface DefaultRetryHandlerOptions { /**
     * The max retry count
     */ maxRetryCount ? : number ; /**
     * Should we retry on the error
     */ shouldRetry ? : ( e : any ) => boolean ; } export function isRetryHandler ( options ? ) { if ( ! options ) { return false ; } return "retry" in options && typeof options . retry === "function" ; } export function resolveRetryHandler ( options ? ) { if ( isRetryHandler ( options ) ) { return options ; } return createRetryHandler ( options ?. maxRetryCount ?? 3 , options ?. shouldRetry ?? isCommonNetworkError ) ; } param maxRetryCount param shouldRetry export function createRetryHandler ( maxRetryCount , shouldRetry ) { const handler = { retry ( url , attempt , error ) { return shouldRetry ( error ) && attempt < maxRetryCount ; } } ; return handler ; }