refactor!: remove error const, change CustomError to PuppeteerError (#11777)

Co-authored-by: Alex Rudenko <OrKoN@users.noreply.github.com>
Co-authored-by: Alex Rudenko <alexrudenko@chromium.org>
This commit is contained in:
Nikolay Vitkov 2024-02-02 13:15:20 +01:00 committed by GitHub
parent ced2235ada
commit b3bfdd2024
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 17 additions and 116 deletions

View File

@ -16,7 +16,6 @@ sidebar_label: API
| [ConsoleMessage](./puppeteer.consolemessage.md) | ConsoleMessage objects are dispatched by page via the 'console' event. |
| [Coverage](./puppeteer.coverage.md) | The Coverage class provides methods to gather information about parts of JavaScript and CSS that were used by the page. |
| [CSSCoverage](./puppeteer.csscoverage.md) | |
| [CustomError](./puppeteer.customerror.md) | |
| [DeviceRequestPrompt](./puppeteer.devicerequestprompt.md) | Device request prompts let you respond to the page requesting for a device through an API like WebBluetooth. |
| [DeviceRequestPromptDevice](./puppeteer.devicerequestpromptdevice.md) | Device in a request prompt. |
| [Dialog](./puppeteer.dialog.md) | Dialog instances are dispatched by the [Page](./puppeteer.page.md) via the <code>dialog</code> event. |
@ -35,6 +34,7 @@ sidebar_label: API
| [ProductLauncher](./puppeteer.productlauncher.md) | Describes a launcher - a class that is able to create and launch a browser instance. |
| [ProtocolError](./puppeteer.protocolerror.md) | ProtocolError is emitted whenever there is an error from the protocol. |
| [Puppeteer](./puppeteer.puppeteer.md) | <p>The main Puppeteer class.</p><p>IMPORTANT: if you are using Puppeteer in a Node environment, you will get an instance of [PuppeteerNode](./puppeteer.puppeteernode.md) when you import or require <code>puppeteer</code>. That class extends <code>Puppeteer</code>, so has all the methods documented below as well as all that are defined on [PuppeteerNode](./puppeteer.puppeteernode.md).</p> |
| [PuppeteerError](./puppeteer.puppeteererror.md) | The base class for all Puppeteer-specific errors |
| [PuppeteerNode](./puppeteer.puppeteernode.md) | <p>Extends the main [Puppeteer](./puppeteer.puppeteer.md) class with Node specific behaviour for fetching and downloading browsers.</p><p>If you're using Puppeteer in a Node environment, this is the class you'll get when you run <code>require('puppeteer')</code> (or the equivalent ES <code>import</code>).</p> |
| [ScreenRecorder](./puppeteer.screenrecorder.md) | |
| [SecurityDetails](./puppeteer.securitydetails.md) | The SecurityDetails class represents the security details of a response that was received over a secure connection. |
@ -127,7 +127,6 @@ sidebar_label: API
| [PDFMargin](./puppeteer.pdfmargin.md) | |
| [PDFOptions](./puppeteer.pdfoptions.md) | Valid options to configure PDF generation via [Page.pdf()](./puppeteer.page.pdf.md). |
| [Point](./puppeteer.point.md) | |
| [PuppeteerErrors](./puppeteer.puppeteererrors.md) | |
| [PuppeteerLaunchOptions](./puppeteer.puppeteerlaunchoptions.md) | |
| [RemoteAddress](./puppeteer.remoteaddress.md) | |
| [ResponseForRequest](./puppeteer.responseforrequest.md) | Required response data to fulfill a request with. |
@ -158,7 +157,6 @@ sidebar_label: API
| [DEFAULT_INTERCEPT_RESOLUTION_PRIORITY](./puppeteer.default_intercept_resolution_priority.md) | The default cooperative request interception resolution priority |
| [defaultArgs](./puppeteer.defaultargs.md) | |
| [devices](./puppeteer.devices.md) | |
| [errors](./puppeteer.errors.md) | |
| [executablePath](./puppeteer.executablepath.md) | |
| [KnownDevices](./puppeteer.knowndevices.md) | A list of devices to be used with [Page.emulate()](./puppeteer.page.emulate.md). |
| [launch](./puppeteer.launch.md) | |

View File

@ -1,33 +0,0 @@
---
sidebar_label: errors
---
# errors variable
> Warning: This API is now obsolete.
>
> Import error classes directly.
>
> Puppeteer methods might throw errors if they are unable to fulfill a request. For example, `page.waitForSelector(selector[, options])` might fail if the selector doesn't match any nodes during the given timeframe.
>
> For certain types of errors Puppeteer uses specific error classes. These classes are available via `puppeteer.errors`.
#### Signature:
```typescript
errors: PuppeteerErrors;
```
## Example
An example of handling a timeout error:
```ts
try {
await page.waitForSelector('.foo');
} catch (e) {
if (e instanceof TimeoutError) {
// Do something if this is a timeout.
}
}
```

View File

@ -9,10 +9,10 @@ ProtocolError is emitted whenever there is an error from the protocol.
#### Signature:
```typescript
export declare class ProtocolError extends CustomError
export declare class ProtocolError extends PuppeteerError
```
**Extends:** [CustomError](./puppeteer.customerror.md)
**Extends:** [PuppeteerError](./puppeteer.puppeteererror.md)
## Properties

View File

@ -1,21 +1,19 @@
---
sidebar_label: CustomError
sidebar_label: PuppeteerError
---
# CustomError class
# PuppeteerError class
> Warning: This API is now obsolete.
>
> Do not use.
The base class for all Puppeteer-specific errors
#### Signature:
```typescript
export declare class CustomError extends Error
export declare class PuppeteerError extends Error
```
**Extends:** Error
## Remarks
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `CustomError` class.
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `PuppeteerError` class.

View File

@ -1,22 +0,0 @@
---
sidebar_label: PuppeteerErrors
---
# PuppeteerErrors interface
> Warning: This API is now obsolete.
>
> Do not use.
#### Signature:
```typescript
export interface PuppeteerErrors
```
## Properties
| Property | Modifiers | Type | Description | Default |
| ------------- | --------- | ---------------------------------------------------- | ----------- | ------- |
| ProtocolError | | typeof [ProtocolError](./puppeteer.protocolerror.md) | | |
| TimeoutError | | typeof [TimeoutError](./puppeteer.timeouterror.md) | | |

View File

@ -9,10 +9,10 @@ TimeoutError is emitted whenever certain operations are terminated due to timeou
#### Signature:
```typescript
export declare class TimeoutError extends CustomError
export declare class TimeoutError extends PuppeteerError
```
**Extends:** [CustomError](./puppeteer.customerror.md)
**Extends:** [PuppeteerError](./puppeteer.puppeteererror.md)
## Remarks

View File

@ -9,7 +9,7 @@ Puppeteer will throw this error if a method is not supported by the currently us
#### Signature:
```typescript
export declare class UnsupportedOperation extends CustomError
export declare class UnsupportedOperation extends PuppeteerError
```
**Extends:** [CustomError](./puppeteer.customerror.md)
**Extends:** [PuppeteerError](./puppeteer.puppeteererror.md)

View File

@ -5,11 +5,11 @@
*/
/**
* @deprecated Do not use.
* The base class for all Puppeteer-specific errors
*
* @public
*/
export class CustomError extends Error {
export class PuppeteerError extends Error {
/**
* @internal
*/
@ -36,14 +36,14 @@ export class CustomError extends Error {
*
* @public
*/
export class TimeoutError extends CustomError {}
export class TimeoutError extends PuppeteerError {}
/**
* ProtocolError is emitted whenever there is an error from the protocol.
*
* @public
*/
export class ProtocolError extends CustomError {
export class ProtocolError extends PuppeteerError {
#code?: number;
#originalMessage = '';
@ -76,49 +76,9 @@ export class ProtocolError extends CustomError {
*
* @public
*/
export class UnsupportedOperation extends CustomError {}
export class UnsupportedOperation extends PuppeteerError {}
/**
* @internal
*/
export class TargetCloseError extends ProtocolError {}
/**
* @deprecated Do not use.
*
* @public
*/
export interface PuppeteerErrors {
TimeoutError: typeof TimeoutError;
ProtocolError: typeof ProtocolError;
}
/**
* @deprecated Import error classes directly.
*
* Puppeteer methods might throw errors if they are unable to fulfill a request.
* For example, `page.waitForSelector(selector[, options])` might fail if the
* selector doesn't match any nodes during the given timeframe.
*
* For certain types of errors Puppeteer uses specific error classes. These
* classes are available via `puppeteer.errors`.
*
* @example
* An example of handling a timeout error:
*
* ```ts
* try {
* await page.waitForSelector('.foo');
* } catch (e) {
* if (e instanceof TimeoutError) {
* // Do something if this is a timeout.
* }
* }
* ```
*
* @public
*/
export const errors: PuppeteerErrors = Object.freeze({
TimeoutError,
ProtocolError,
});