import { ResourceMetadata } from "./metadata" ; import { Segment } from "./segment" ; export type DownloadFailedReason = "DownloadAborted" | "DownloadValidationFailed" | "GeneralDownloadException" | NetworkErrorType ; /**
 * Download
 */ export class DownloadError extends Error { constructor ( readonly error , readonly metadata , readonly headers , readonly destination , readonly segments , readonly segmentErrors ) { super ( `The download failed! ${ error }` ) ; } } export type NetworkErrorType = "ConnectionReset" | "ConnectionTimeout" | "OperationCancelled" | "ProtocolError" ; export function resolveNetworkErrorType ( e ) { if ( e . code === "ECONNRESET" ) { return "ConnectionReset" ; } if ( e . code === "ETIMEDOUT" ) { return "ConnectionTimeout" ; } if ( e . code === "EPROTO" ) { return "ProtocolError" ; } if ( e . code === "ECANCELED" ) { return "OperationCancelled" ; } } param e export function isCommonNetworkError ( e ) { if ( typeof e . code === "string" ) { return e . code === "ECONNRESET" || e . code === "ETIMEDOUT" || e . code === "EPROTO" || e . code === "ECANCELED" ; } return false ; }