From 7b533ff1509a08d8c888f1f92b722d5985b7fa7f Mon Sep 17 00:00:00 2001 From: Chris Jordan Date: Fri, 19 Apr 2024 10:03:49 -0400 Subject: [PATCH] added error handling --- src/datasource/graphene/backend.ts | 39 ++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/datasource/graphene/backend.ts b/src/datasource/graphene/backend.ts index 61da5d7b2..4397d4bc9 100644 --- a/src/datasource/graphene/backend.ts +++ b/src/datasource/graphene/backend.ts @@ -265,7 +265,7 @@ function decodeChunkedGraphChunk(leaves: string[]) { class BulkRequestProxy { pendingRequests = new Map< string, - [Signal<(request: any) => void>, Uint64Set] + [Signal<(response: any) => void>, Uint64Set] >(); constructor( @@ -291,26 +291,35 @@ class BulkRequestProxy { } const [_, segments] = pendingRequest; _; - const response = await cancellableFetchSpecialOk( - credentialsProvider, - `${parameters.url}/leaves_many?int64_as_str=1&bounds=${bounds}`, - { - method: "POST", - body: JSON.stringify({ - node_ids: [...segments], - }), - }, - responseJson, - ); - signal.dispatch(response); + console.log(segments.size); + try { + const response = await cancellableFetchSpecialOk( + credentialsProvider, + `${parameters.url}/leaves_many?int64_as_str=1&bounds=${bounds}`, + { + method: "POST", + body: JSON.stringify({ + node_ids: [...segments], + }), + }, + responseJson, + ); + signal.dispatch(response); + } catch (e) { + signal.dispatch(e); + } }, 0); } const [request, segments] = pendingRequest; segments.add(segment); - return new Promise((f) => { + return new Promise((f, r) => { const unregister = request.add((response) => { - f(response[segment.toJSON()]); unregister(); + if (response instanceof Error) { + r(response); + } else { + f(response[segment.toJSON()]); + } }); }); }