-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherr-invalid-url.ts
110 lines (103 loc) · 2.71 KB
/
err-invalid-url.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* @file Errors - ERR_INVALID_URL
* @module errnode/errors/ERR_INVALID_URL
* @see https://github.com/nodejs/node/blob/v22.7.0/lib/internal/errors.js#L1532-L1542
*/
import E from '#e'
import { codes } from '#src/enums'
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
/**
* `ERR_INVALID_URL` schema.
*
* @see {@linkcode NodeError}
* @see https://nodejs.org/api/errors.html#err_invalid_url
*
* @extends {NodeError<codes.ERR_INVALID_URL>}
* @extends {TypeError}
*/
interface ErrInvalidUrl extends NodeError<codes.ERR_INVALID_URL>, TypeError {
/**
* Base URL resolved against if `input` is not absolute.
*/
base?: URL | string | null | undefined
/**
* URL that failed to parse.
*
* @example
* 'http://[127.0.0.1\x00c8763]:8000/'
*/
input: string
}
/**
* `ERR_INVALID_URL` message arguments.
*/
type Args = [input: string, base?: URL | string | null | undefined]
/**
* `ERR_INVALID_URL` constructor.
*
* @see {@linkcode Args}
* @see {@linkcode ErrInvalidUrl}
* @see {@linkcode NodeErrorConstructor}
*
* @extends {NodeErrorConstructor<ErrInvalidUrl,Args>}
*/
interface ErrInvalidUrlConstructor
extends NodeErrorConstructor<ErrInvalidUrl, Args> {
/**
* Create a new `ERR_INVALID_URL` error.
*
* @see {@linkcode ErrInvalidUrl}
*
* @param {string} input
* URL that failed to parse
* @param {URL | string | null | undefined} [base]
* Base URL resolved against if `input` is not absolute
* @return {ErrInvalidUrl}
*/
new (input: string, base?: URL | string | null | undefined): ErrInvalidUrl
}
/**
* `ERR_INVALID_URL` model.
*
* Thrown when an invalid URL is passed to a [WHATWG][1] [`URL` constructor][2]
* or [`url.parse()`][3] to be parsed.
*
* [1]: https://nodejs.org/api/url.html#the-whatwg-url-api
* [2]: https://nodejs.org/api/url.html#new-urlinput-base
* [3]: https://nodejs.org/api/url.html#urlparseurlstring-parsequerystring-slashesdenotehost
*
* @see {@linkcode ErrInvalidUrlConstructor}
*
* @type {ErrInvalidUrlConstructor}
*
* @class
*/
const ERR_INVALID_URL: ErrInvalidUrlConstructor = E(
codes.ERR_INVALID_URL,
TypeError,
/**
* @this {ErrInvalidUrl}
*
* @param {string} input
* URL that failed to parse
* @param {URL | string | null | undefined} [base]
* Base URL resolved against if `input` is not absolute
* @return {string}
* Error message
*/
function message(
this: ErrInvalidUrl,
input: string,
base: URL | string | null | undefined = null
): string {
this.input = input
if (base !== null) this.base = base
return 'Invalid URL'
}
)
export {
ERR_INVALID_URL as default,
type ErrInvalidUrl,
type Args as ErrInvalidUrlArgs,
type ErrInvalidUrlConstructor
}