1'use strict' 2 3class InvalidProxyProtocolError extends Error { 4 constructor (url) { 5 super(`Invalid protocol \`${url.protocol}\` connecting to proxy \`${url.host}\``) 6 this.code = 'EINVALIDPROXY' 7 this.proxy = url 8 } 9} 10 11class ConnectionTimeoutError extends Error { 12 constructor (host) { 13 super(`Timeout connecting to host \`${host}\``) 14 this.code = 'ECONNECTIONTIMEOUT' 15 this.host = host 16 } 17} 18 19class IdleTimeoutError extends Error { 20 constructor (host) { 21 super(`Idle timeout reached for host \`${host}\``) 22 this.code = 'EIDLETIMEOUT' 23 this.host = host 24 } 25} 26 27class ResponseTimeoutError extends Error { 28 constructor (request, proxy) { 29 let msg = 'Response timeout ' 30 if (proxy) { 31 msg += `from proxy \`${proxy.host}\` ` 32 } 33 msg += `connecting to host \`${request.host}\`` 34 super(msg) 35 this.code = 'ERESPONSETIMEOUT' 36 this.proxy = proxy 37 this.request = request 38 } 39} 40 41class TransferTimeoutError extends Error { 42 constructor (request, proxy) { 43 let msg = 'Transfer timeout ' 44 if (proxy) { 45 msg += `from proxy \`${proxy.host}\` ` 46 } 47 msg += `for \`${request.host}\`` 48 super(msg) 49 this.code = 'ETRANSFERTIMEOUT' 50 this.proxy = proxy 51 this.request = request 52 } 53} 54 55module.exports = { 56 InvalidProxyProtocolError, 57 ConnectionTimeoutError, 58 IdleTimeoutError, 59 ResponseTimeoutError, 60 TransferTimeoutError, 61} 62