From a4a90d7456e2a1521fe46ed73f3cc3fa6174feaa Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 8 Oct 2024 09:56:51 +0100 Subject: [PATCH] Fix tests. --- .../backend-core/src/db/couch/DatabaseImpl.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/backend-core/src/db/couch/DatabaseImpl.ts b/packages/backend-core/src/db/couch/DatabaseImpl.ts index 2ca52a2dce..1213dde8f5 100644 --- a/packages/backend-core/src/db/couch/DatabaseImpl.ts +++ b/packages/backend-core/src/db/couch/DatabaseImpl.ts @@ -371,15 +371,21 @@ export class DatabaseImpl implements Database { return this.performCall(() => { return async () => { const response = await directCouchUrlCall(args) - if (response.status >= 300) { - const text = await response.text() - console.error(`SQS error: ${text}`) - throw new CouchDBError( - "error while running SQS query, please try again later", - { name: "sqs_error", status: response.status } - ) + const text = await response.text() + if (response.status > 300) { + let json + try { + json = JSON.parse(text) + } catch (err) { + console.error(`SQS error: ${text}`) + throw new CouchDBError( + "error while running SQS query, please try again later", + { name: "sqs_error", status: response.status } + ) + } + throw json } - return (await response.json()) as T + return JSON.parse(text) as T } }) }