You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// TODO There has got to be some type magic that makes this manual copying unnecessary
import{Endpoint}from'datadirect';import{Authenticated}from'./Authenticated.js';typeEndpointOptions<PextendsEndpoint.Payload>={payload: P;pathParams?: Record<string,string|number|boolean>;logBodyOnError?: boolean;};exporttypeBoundEndpoint<PextendsEndpoint.Payload,RextendsEndpoint.Response>=(options: EndpointOptions<P>)=>Promise<R>;typeFetchError={error: Error;response: Response;body: string;}&Endpoint.FetchParams;functionisFetchError(e: unknown): e is FetchError{returne!=null&&typeofe==='object'&&'error'ine&&'body'ine;}exportclassFetchableextendsAuthenticated{protectedbindEndpoint<PextendsEndpoint.Payload,RextendsEndpoint.Response>(module: Endpoint.Module<P>): BoundEndpoint<P,R>{returnasync({
payload,
pathParams ={},
logBodyOnError =false}: EndpointOptions<P>)=>{const{ input, init }=module.prepare(payload,this.page.url());constresult: R|FetchError=awaitthis.page.evaluate(async(params)=>{const{ input, init }=params;letbody: R|undefined|string=undefined;letresponse: Response|undefined=undefined;try{response=awaitfetch(input,init);body=awaitresponse.text();returnJSON.parse(body)asR;}catch(error){return{error: errorasError,
input,
init,// TODO There has got to be some type magic that makes this manual copying unnecessaryresponse: {url: response?.url,redirected: response?.redirected,type: response?.type,status: response?.status,statusText: response?.statusText,headers: response?.headers},
body
}asFetchError;}},{input: Endpoint.preparePath(input,pathParams), init });if(isFetchError(result)){const{ error, body, ...rest}=result;if(logBodyOnError){console.error(rest);console.error(body);}throwerror;}returnresult;};}}
The text was updated successfully, but these errors were encountered:
battis
changed the title
There has got to be some type magic that makes this manual copying unnecessary
Redundant piecemeal copying of fetch response
Jan 3, 2025
myschoolapp-reporting/packages/datadirect-puppeteer/src/PuppeteerSession/Fetchable.ts
Line 50 in a835ed2
The text was updated successfully, but these errors were encountered: