Skip to main content
Version: 23.8.0

HTTPRequest.failure() 方法

¥HTTPRequest.failure() method

访问有关请求失败的信息。

¥Access information about the request's failure.

签名

¥Signature

class HTTPRequest {
abstract failure(): {
errorText: string;
} | null;
}

Returns:

{ errorText: string; }

| 无效的

¥| null

null 除非请求失败。如果请求失败,则可以返回一个带有 errorText 的对象,其中包含人类可读的错误消息,例如 net::ERR_FAILED。如果请求失败,不保证会有失败文本。

¥null unless the request failed. If the request fails this can return an object with errorText containing a human-readable error message, e.g. net::ERR_FAILED. It is not guaranteed that there will be failure text if the request fails.

备注

¥Remarks

示例

¥Example

记录所有失败请求的示例:

¥Example of logging all failed requests:

page.on('requestfailed', request => {
console.log(request.url() + ' ' + request.failure().errorText);
});