Merge pull request #14717 from Budibase/graceful-sqs-5xx-error-handling

Fix SQS error handling.
This commit is contained in:
Sam Rose 2024-10-08 10:08:02 +01:00 committed by GitHub
commit be4bc43317
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 2 deletions

View File

@ -371,11 +371,21 @@ export class DatabaseImpl implements Database {
return this.performCall(() => { return this.performCall(() => {
return async () => { return async () => {
const response = await directCouchUrlCall(args) const response = await directCouchUrlCall(args)
const json = await response.json() const text = await response.text()
if (response.status > 300) { 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 throw json
} }
return json as T return JSON.parse(text) as T
} }
}) })
} }