UNPKG

1.13 kBPlain TextView Raw
1import 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 */
8export 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 */
30export 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 */
37export const InvalidPackageVersionError = makeError(
38 'InvalidPackageVersionError'
39);