From d6cba627853a832afcc410f7a70b4c82ba717abd Mon Sep 17 00:00:00 2001 From: Alessandro Pagnin Date: Thu, 26 Feb 2026 16:19:31 +0100 Subject: [PATCH] fix: return as client error --- .../publishPersistedOperations.ts | 13 ++++++---- .../test/persisted-operations.test.ts | 24 ++++++++----------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/controlplane/src/core/bufservices/persisted-operation/publishPersistedOperations.ts b/controlplane/src/core/bufservices/persisted-operation/publishPersistedOperations.ts index b417e52898..333368c336 100644 --- a/controlplane/src/core/bufservices/persisted-operation/publishPersistedOperations.ts +++ b/controlplane/src/core/bufservices/persisted-operation/publishPersistedOperations.ts @@ -1,7 +1,7 @@ import crypto from 'node:crypto'; import { PlainMessage } from '@bufbuild/protobuf'; import pLimit from 'p-limit'; -import { Code, ConnectError, HandlerContext } from '@connectrpc/connect'; +import { HandlerContext } from '@connectrpc/connect'; import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb'; import { PublishedOperation, @@ -47,10 +47,13 @@ export function publishPersistedOperations( } if (req.operations.length > MAX_PERSISTED_OPERATIONS) { - throw new ConnectError( - `Payload Too Large: max ${MAX_PERSISTED_OPERATIONS} operations per request`, - Code.ResourceExhausted, - ); + return { + response: { + code: EnumStatusCode.ERR, + details: `Payload Too Large: max ${MAX_PERSISTED_OPERATIONS} operations per request`, + }, + operations: [], + }; } const userId = authContext.userId; diff --git a/controlplane/test/persisted-operations.test.ts b/controlplane/test/persisted-operations.test.ts index 3206adeca9..ad4c8e364a 100644 --- a/controlplane/test/persisted-operations.test.ts +++ b/controlplane/test/persisted-operations.test.ts @@ -159,20 +159,16 @@ describe('Persisted operations', (ctx) => { contents: `query { hello }`, })); - let error: unknown; - try { - await client.publishPersistedOperations({ - fedGraphName, - namespace: 'default', - clientName: 'test-client', - operations, - }); - } catch (err) { - error = err; - } - - expect(error).toBeInstanceOf(ConnectError); - expect(error).toMatchObject({ code: Code.ResourceExhausted }); + const overLimitResp = await client.publishPersistedOperations({ + fedGraphName, + namespace: 'default', + clientName: 'test-client', + operations, + }); + + expect(overLimitResp.response?.code).toBe(EnumStatusCode.ERR); + expect(overLimitResp.response?.details).toContain('Payload Too Large: max 100 operations per request'); + expect(overLimitResp.operations).toEqual([]); }); test('Should not publish persisted operations with an invalid federated graph name', async (testContext) => {