1 | import makeError, { BaseError } from 'make-error';
|
2 |
|
3 | /**
|
4 | * `FetchError` represents an error that happened when fetching a URL.
|
5 | *
|
6 | * The `instanceof` operator can be used to check for this error.
|
7 | */
|
8 | export class FetchError extends BaseError {
|
9 | constructor(
|
10 | /** URL originally fetched */
|
11 | readonly url: string,
|
12 |
|
13 | /** Response received */
|
14 | readonly response: Response
|
15 | ) {
|
16 | super(
|
17 | `fetch: request to ${url} failed with status ${response.statusText}`
|
18 | );
|
19 | }
|
20 | }
|
21 |
|
22 | /**
|
23 | * `InvalidPackageNameError` is thrown when the name of a package
|
24 | * is not valid according to the npm registry naming rules.
|
25 | *
|
26 | * The `instanceof` operator can be used to check for this error.
|
27 | *
|
28 | * @see {@link https://www.npmjs.com/package/validate-npm-package-name}
|
29 | */
|
30 | export const InvalidPackageNameError = makeError('InvalidPackageNameError');
|
31 |
|
32 | /**
|
33 | * `InvalidPackageVersionError` is thrown when a package's version does not exist.
|
34 | *
|
35 | * The `instanceof` operator can be used to check for this error.
|
36 | */
|
37 | export const InvalidPackageVersionError = makeError(
|
38 | 'InvalidPackageVersionError'
|
39 | );
|