errors.js 1.4 KB

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