1'use strict' 2 3class UndiciError extends Error { 4 constructor (message) { 5 super(message) 6 this.name = 'UndiciError' 7 this.code = 'UND_ERR' 8 } 9} 10 11class ConnectTimeoutError extends UndiciError { 12 constructor (message) { 13 super(message) 14 Error.captureStackTrace(this, ConnectTimeoutError) 15 this.name = 'ConnectTimeoutError' 16 this.message = message || 'Connect Timeout Error' 17 this.code = 'UND_ERR_CONNECT_TIMEOUT' 18 } 19} 20 21class HeadersTimeoutError extends UndiciError { 22 constructor (message) { 23 super(message) 24 Error.captureStackTrace(this, HeadersTimeoutError) 25 this.name = 'HeadersTimeoutError' 26 this.message = message || 'Headers Timeout Error' 27 this.code = 'UND_ERR_HEADERS_TIMEOUT' 28 } 29} 30 31class HeadersOverflowError extends UndiciError { 32 constructor (message) { 33 super(message) 34 Error.captureStackTrace(this, HeadersOverflowError) 35 this.name = 'HeadersOverflowError' 36 this.message = message || 'Headers Overflow Error' 37 this.code = 'UND_ERR_HEADERS_OVERFLOW' 38 } 39} 40 41class BodyTimeoutError extends UndiciError { 42 constructor (message) { 43 super(message) 44 Error.captureStackTrace(this, BodyTimeoutError) 45 this.name = 'BodyTimeoutError' 46 this.message = message || 'Body Timeout Error' 47 this.code = 'UND_ERR_BODY_TIMEOUT' 48 } 49} 50 51class ResponseStatusCodeError extends UndiciError { 52 constructor (message, statusCode, headers, body) { 53 super(message) 54 Error.captureStackTrace(this, ResponseStatusCodeError) 55 this.name = 'ResponseStatusCodeError' 56 this.message = message || 'Response Status Code Error' 57 this.code = 'UND_ERR_RESPONSE_STATUS_CODE' 58 this.body = body 59 this.status = statusCode 60 this.statusCode = statusCode 61 this.headers = headers 62 } 63} 64 65class InvalidArgumentError extends UndiciError { 66 constructor (message) { 67 super(message) 68 Error.captureStackTrace(this, InvalidArgumentError) 69 this.name = 'InvalidArgumentError' 70 this.message = message || 'Invalid Argument Error' 71 this.code = 'UND_ERR_INVALID_ARG' 72 } 73} 74 75class InvalidReturnValueError extends UndiciError { 76 constructor (message) { 77 super(message) 78 Error.captureStackTrace(this, InvalidReturnValueError) 79 this.name = 'InvalidReturnValueError' 80 this.message = message || 'Invalid Return Value Error' 81 this.code = 'UND_ERR_INVALID_RETURN_VALUE' 82 } 83} 84 85class RequestAbortedError extends UndiciError { 86 constructor (message) { 87 super(message) 88 Error.captureStackTrace(this, RequestAbortedError) 89 this.name = 'AbortError' 90 this.message = message || 'Request aborted' 91 this.code = 'UND_ERR_ABORTED' 92 } 93} 94 95class InformationalError extends UndiciError { 96 constructor (message) { 97 super(message) 98 Error.captureStackTrace(this, InformationalError) 99 this.name = 'InformationalError' 100 this.message = message || 'Request information' 101 this.code = 'UND_ERR_INFO' 102 } 103} 104 105class RequestContentLengthMismatchError extends UndiciError { 106 constructor (message) { 107 super(message) 108 Error.captureStackTrace(this, RequestContentLengthMismatchError) 109 this.name = 'RequestContentLengthMismatchError' 110 this.message = message || 'Request body length does not match content-length header' 111 this.code = 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH' 112 } 113} 114 115class ResponseContentLengthMismatchError extends UndiciError { 116 constructor (message) { 117 super(message) 118 Error.captureStackTrace(this, ResponseContentLengthMismatchError) 119 this.name = 'ResponseContentLengthMismatchError' 120 this.message = message || 'Response body length does not match content-length header' 121 this.code = 'UND_ERR_RES_CONTENT_LENGTH_MISMATCH' 122 } 123} 124 125class ClientDestroyedError extends UndiciError { 126 constructor (message) { 127 super(message) 128 Error.captureStackTrace(this, ClientDestroyedError) 129 this.name = 'ClientDestroyedError' 130 this.message = message || 'The client is destroyed' 131 this.code = 'UND_ERR_DESTROYED' 132 } 133} 134 135class ClientClosedError extends UndiciError { 136 constructor (message) { 137 super(message) 138 Error.captureStackTrace(this, ClientClosedError) 139 this.name = 'ClientClosedError' 140 this.message = message || 'The client is closed' 141 this.code = 'UND_ERR_CLOSED' 142 } 143} 144 145class SocketError extends UndiciError { 146 constructor (message, socket) { 147 super(message) 148 Error.captureStackTrace(this, SocketError) 149 this.name = 'SocketError' 150 this.message = message || 'Socket error' 151 this.code = 'UND_ERR_SOCKET' 152 this.socket = socket 153 } 154} 155 156class NotSupportedError extends UndiciError { 157 constructor (message) { 158 super(message) 159 Error.captureStackTrace(this, NotSupportedError) 160 this.name = 'NotSupportedError' 161 this.message = message || 'Not supported error' 162 this.code = 'UND_ERR_NOT_SUPPORTED' 163 } 164} 165 166class BalancedPoolMissingUpstreamError extends UndiciError { 167 constructor (message) { 168 super(message) 169 Error.captureStackTrace(this, NotSupportedError) 170 this.name = 'MissingUpstreamError' 171 this.message = message || 'No upstream has been added to the BalancedPool' 172 this.code = 'UND_ERR_BPL_MISSING_UPSTREAM' 173 } 174} 175 176class HTTPParserError extends Error { 177 constructor (message, code, data) { 178 super(message) 179 Error.captureStackTrace(this, HTTPParserError) 180 this.name = 'HTTPParserError' 181 this.code = code ? `HPE_${code}` : undefined 182 this.data = data ? data.toString() : undefined 183 } 184} 185 186class ResponseExceededMaxSizeError extends UndiciError { 187 constructor (message) { 188 super(message) 189 Error.captureStackTrace(this, ResponseExceededMaxSizeError) 190 this.name = 'ResponseExceededMaxSizeError' 191 this.message = message || 'Response content exceeded max size' 192 this.code = 'UND_ERR_RES_EXCEEDED_MAX_SIZE' 193 } 194} 195 196class RequestRetryError extends UndiciError { 197 constructor (message, code, { headers, data }) { 198 super(message) 199 Error.captureStackTrace(this, RequestRetryError) 200 this.name = 'RequestRetryError' 201 this.message = message || 'Request retry error' 202 this.code = 'UND_ERR_REQ_RETRY' 203 this.statusCode = code 204 this.data = data 205 this.headers = headers 206 } 207} 208 209module.exports = { 210 HTTPParserError, 211 UndiciError, 212 HeadersTimeoutError, 213 HeadersOverflowError, 214 BodyTimeoutError, 215 RequestContentLengthMismatchError, 216 ConnectTimeoutError, 217 ResponseStatusCodeError, 218 InvalidArgumentError, 219 InvalidReturnValueError, 220 RequestAbortedError, 221 ClientDestroyedError, 222 ClientClosedError, 223 InformationalError, 224 SocketError, 225 NotSupportedError, 226 ResponseContentLengthMismatchError, 227 BalancedPoolMissingUpstreamError, 228 ResponseExceededMaxSizeError, 229 RequestRetryError 230} 231