errors.d.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import { IncomingHttpHeaders } from "./header";
  2. import Client from './client'
  3. export default Errors
  4. declare namespace Errors {
  5. export class UndiciError extends Error {
  6. name: string;
  7. code: string;
  8. }
  9. /** Connect timeout error. */
  10. export class ConnectTimeoutError extends UndiciError {
  11. name: 'ConnectTimeoutError';
  12. code: 'UND_ERR_CONNECT_TIMEOUT';
  13. }
  14. /** A header exceeds the `headersTimeout` option. */
  15. export class HeadersTimeoutError extends UndiciError {
  16. name: 'HeadersTimeoutError';
  17. code: 'UND_ERR_HEADERS_TIMEOUT';
  18. }
  19. /** Headers overflow error. */
  20. export class HeadersOverflowError extends UndiciError {
  21. name: 'HeadersOverflowError'
  22. code: 'UND_ERR_HEADERS_OVERFLOW'
  23. }
  24. /** A body exceeds the `bodyTimeout` option. */
  25. export class BodyTimeoutError extends UndiciError {
  26. name: 'BodyTimeoutError';
  27. code: 'UND_ERR_BODY_TIMEOUT';
  28. }
  29. export class ResponseStatusCodeError extends UndiciError {
  30. constructor (
  31. message?: string,
  32. statusCode?: number,
  33. headers?: IncomingHttpHeaders | string[] | null,
  34. body?: null | Record<string, any> | string
  35. );
  36. name: 'ResponseStatusCodeError';
  37. code: 'UND_ERR_RESPONSE_STATUS_CODE';
  38. body: null | Record<string, any> | string
  39. status: number
  40. statusCode: number
  41. headers: IncomingHttpHeaders | string[] | null;
  42. }
  43. /** Passed an invalid argument. */
  44. export class InvalidArgumentError extends UndiciError {
  45. name: 'InvalidArgumentError';
  46. code: 'UND_ERR_INVALID_ARG';
  47. }
  48. /** Returned an invalid value. */
  49. export class InvalidReturnValueError extends UndiciError {
  50. name: 'InvalidReturnValueError';
  51. code: 'UND_ERR_INVALID_RETURN_VALUE';
  52. }
  53. /** The request has been aborted by the user. */
  54. export class RequestAbortedError extends UndiciError {
  55. name: 'AbortError';
  56. code: 'UND_ERR_ABORTED';
  57. }
  58. /** Expected error with reason. */
  59. export class InformationalError extends UndiciError {
  60. name: 'InformationalError';
  61. code: 'UND_ERR_INFO';
  62. }
  63. /** Request body length does not match content-length header. */
  64. export class RequestContentLengthMismatchError extends UndiciError {
  65. name: 'RequestContentLengthMismatchError';
  66. code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH';
  67. }
  68. /** Response body length does not match content-length header. */
  69. export class ResponseContentLengthMismatchError extends UndiciError {
  70. name: 'ResponseContentLengthMismatchError';
  71. code: 'UND_ERR_RES_CONTENT_LENGTH_MISMATCH';
  72. }
  73. /** Trying to use a destroyed client. */
  74. export class ClientDestroyedError extends UndiciError {
  75. name: 'ClientDestroyedError';
  76. code: 'UND_ERR_DESTROYED';
  77. }
  78. /** Trying to use a closed client. */
  79. export class ClientClosedError extends UndiciError {
  80. name: 'ClientClosedError';
  81. code: 'UND_ERR_CLOSED';
  82. }
  83. /** There is an error with the socket. */
  84. export class SocketError extends UndiciError {
  85. name: 'SocketError';
  86. code: 'UND_ERR_SOCKET';
  87. socket: Client.SocketInfo | null
  88. }
  89. /** Encountered unsupported functionality. */
  90. export class NotSupportedError extends UndiciError {
  91. name: 'NotSupportedError';
  92. code: 'UND_ERR_NOT_SUPPORTED';
  93. }
  94. /** No upstream has been added to the BalancedPool. */
  95. export class BalancedPoolMissingUpstreamError extends UndiciError {
  96. name: 'MissingUpstreamError';
  97. code: 'UND_ERR_BPL_MISSING_UPSTREAM';
  98. }
  99. export class HTTPParserError extends UndiciError {
  100. name: 'HTTPParserError';
  101. code: string;
  102. }
  103. /** The response exceed the length allowed. */
  104. export class ResponseExceededMaxSizeError extends UndiciError {
  105. name: 'ResponseExceededMaxSizeError';
  106. code: 'UND_ERR_RES_EXCEEDED_MAX_SIZE';
  107. }
  108. }