feat(rpc): update Response.finished to return string instead of Error (#3071)
This commit is contained in:
parent
47e30f047b
commit
3dd61629e0
|
|
@ -243,7 +243,7 @@ export class CRNetworkManager {
|
||||||
|
|
||||||
_handleRequestRedirect(request: InterceptableRequest, responsePayload: Protocol.Network.Response) {
|
_handleRequestRedirect(request: InterceptableRequest, responsePayload: Protocol.Network.Response) {
|
||||||
const response = this._createResponse(request, responsePayload);
|
const response = this._createResponse(request, responsePayload);
|
||||||
response._requestFinished(new Error('Response body is unavailable for redirect responses'));
|
response._requestFinished('Response body is unavailable for redirect responses');
|
||||||
this._requestIdToRequest.delete(request._requestId);
|
this._requestIdToRequest.delete(request._requestId);
|
||||||
if (request._interceptionId)
|
if (request._interceptionId)
|
||||||
this._attemptedAuthentications.delete(request._interceptionId);
|
this._attemptedAuthentications.delete(request._interceptionId);
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ export class FFNetworkManager {
|
||||||
// Keep redirected requests in the map for future reference as redirectedFrom.
|
// Keep redirected requests in the map for future reference as redirectedFrom.
|
||||||
const isRedirected = response.status() >= 300 && response.status() <= 399;
|
const isRedirected = response.status() >= 300 && response.status() <= 399;
|
||||||
if (isRedirected) {
|
if (isRedirected) {
|
||||||
response._requestFinished(new Error('Response body is unavailable for redirect responses'));
|
response._requestFinished('Response body is unavailable for redirect responses');
|
||||||
} else {
|
} else {
|
||||||
this._requests.delete(request._id);
|
this._requests.delete(request._id);
|
||||||
response._requestFinished();
|
response._requestFinished();
|
||||||
|
|
|
||||||
|
|
@ -234,8 +234,8 @@ type GetResponseBodyCallback = () => Promise<Buffer>;
|
||||||
export class Response {
|
export class Response {
|
||||||
private _request: Request;
|
private _request: Request;
|
||||||
private _contentPromise: Promise<Buffer> | null = null;
|
private _contentPromise: Promise<Buffer> | null = null;
|
||||||
_finishedPromise: Promise<Error | null>;
|
_finishedPromise: Promise<{ error?: string }>;
|
||||||
private _finishedPromiseCallback: any;
|
private _finishedPromiseCallback: (arg: { error?: string }) => void = () => {};
|
||||||
private _status: number;
|
private _status: number;
|
||||||
private _statusText: string;
|
private _statusText: string;
|
||||||
private _url: string;
|
private _url: string;
|
||||||
|
|
@ -255,8 +255,8 @@ export class Response {
|
||||||
this._request._setResponse(this);
|
this._request._setResponse(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
_requestFinished(error?: Error) {
|
_requestFinished(error?: string) {
|
||||||
this._finishedPromiseCallback.call(null, error || null);
|
this._finishedPromiseCallback({ error });
|
||||||
}
|
}
|
||||||
|
|
||||||
url(): string {
|
url(): string {
|
||||||
|
|
@ -280,14 +280,14 @@ export class Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
finished(): Promise<Error | null> {
|
finished(): Promise<Error | null> {
|
||||||
return this._finishedPromise;
|
return this._finishedPromise.then(({ error }) => error ? new Error(error) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
body(): Promise<Buffer> {
|
body(): Promise<Buffer> {
|
||||||
if (!this._contentPromise) {
|
if (!this._contentPromise) {
|
||||||
this._contentPromise = this._finishedPromise.then(async error => {
|
this._contentPromise = this._finishedPromise.then(async ({ error }) => {
|
||||||
if (error)
|
if (error)
|
||||||
throw error;
|
throw new Error(error);
|
||||||
return this._getResponseBodyCallback();
|
return this._getResponseBodyCallback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1472,7 +1472,7 @@ export type ResponseBodyResult = {
|
||||||
};
|
};
|
||||||
export type ResponseFinishedParams = {};
|
export type ResponseFinishedParams = {};
|
||||||
export type ResponseFinishedResult = {
|
export type ResponseFinishedResult = {
|
||||||
error?: SerializedError,
|
error?: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------- ConsoleMessage -----------
|
// ----------- ConsoleMessage -----------
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import * as types from '../../types';
|
||||||
import { RequestChannel, ResponseChannel, RouteChannel, RequestInitializer, ResponseInitializer, RouteInitializer } from '../channels';
|
import { RequestChannel, ResponseChannel, RouteChannel, RequestInitializer, ResponseInitializer, RouteInitializer } from '../channels';
|
||||||
import { ChannelOwner } from './channelOwner';
|
import { ChannelOwner } from './channelOwner';
|
||||||
import { Frame } from './frame';
|
import { Frame } from './frame';
|
||||||
import { normalizeFulfillParameters, headersArrayToObject, normalizeContinueOverrides, parseError } from '../serializers';
|
import { normalizeFulfillParameters, headersArrayToObject, normalizeContinueOverrides } from '../serializers';
|
||||||
|
|
||||||
export type NetworkCookie = {
|
export type NetworkCookie = {
|
||||||
name: string,
|
name: string,
|
||||||
|
|
@ -206,7 +206,7 @@ export class Response extends ChannelOwner<ResponseChannel, ResponseInitializer>
|
||||||
async finished(): Promise<Error | null> {
|
async finished(): Promise<Error | null> {
|
||||||
const result = await this._channel.finished();
|
const result = await this._channel.finished();
|
||||||
if (result.error)
|
if (result.error)
|
||||||
return parseError(result.error);
|
return new Error(result.error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1340,7 +1340,7 @@ interface Response
|
||||||
|
|
||||||
command finished
|
command finished
|
||||||
returns
|
returns
|
||||||
error?: SerializedError
|
error?: string
|
||||||
|
|
||||||
interface ConsoleMessage
|
interface ConsoleMessage
|
||||||
initializer
|
initializer
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Request, Response, Route } from '../../network';
|
import { Request, Response, Route } from '../../network';
|
||||||
import { RequestChannel, ResponseChannel, RouteChannel, ResponseInitializer, RequestInitializer, RouteInitializer, Binary, SerializedError } from '../channels';
|
import { RequestChannel, ResponseChannel, RouteChannel, ResponseInitializer, RequestInitializer, RouteInitializer, Binary } from '../channels';
|
||||||
import { Dispatcher, DispatcherScope, lookupNullableDispatcher, existingDispatcher } from './dispatcher';
|
import { Dispatcher, DispatcherScope, lookupNullableDispatcher, existingDispatcher } from './dispatcher';
|
||||||
import { FrameDispatcher } from './frameDispatcher';
|
import { FrameDispatcher } from './frameDispatcher';
|
||||||
import { headersObjectToArray, headersArrayToObject, serializeError } from '../serializers';
|
import { headersObjectToArray, headersArrayToObject } from '../serializers';
|
||||||
import * as types from '../../types';
|
import * as types from '../../types';
|
||||||
|
|
||||||
export class RequestDispatcher extends Dispatcher<Request, RequestInitializer> implements RequestChannel {
|
export class RequestDispatcher extends Dispatcher<Request, RequestInitializer> implements RequestChannel {
|
||||||
|
|
@ -64,9 +64,8 @@ export class ResponseDispatcher extends Dispatcher<Response, ResponseInitializer
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async finished(): Promise<{ error?: SerializedError }> {
|
async finished(): Promise<{ error?: string }> {
|
||||||
const error = await this._object.finished();
|
return await this._object._finishedPromise;
|
||||||
return { error: error ? serializeError(error) : undefined };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async body(): Promise<{ binary: Binary }> {
|
async body(): Promise<{ binary: Binary }> {
|
||||||
|
|
|
||||||
|
|
@ -853,7 +853,7 @@ export class WKPage implements PageDelegate {
|
||||||
|
|
||||||
private _handleRequestRedirect(request: WKInterceptableRequest, responsePayload: Protocol.Network.Response) {
|
private _handleRequestRedirect(request: WKInterceptableRequest, responsePayload: Protocol.Network.Response) {
|
||||||
const response = request.createResponse(responsePayload);
|
const response = request.createResponse(responsePayload);
|
||||||
response._requestFinished(new Error('Response body is unavailable for redirect responses'));
|
response._requestFinished('Response body is unavailable for redirect responses');
|
||||||
this._requestIdToRequest.delete(request._requestId);
|
this._requestIdToRequest.delete(request._requestId);
|
||||||
this._page._frameManager.requestReceivedResponse(response);
|
this._page._frameManager.requestReceivedResponse(response);
|
||||||
this._page._frameManager.requestFinished(request.request);
|
this._page._frameManager.requestFinished(request.request);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue