diff --git a/packages/thrift-client/src/main/connections/HttpConnection.ts b/packages/thrift-client/src/main/connections/HttpConnection.ts index 62284a48..f917ea91 100644 --- a/packages/thrift-client/src/main/connections/HttpConnection.ts +++ b/packages/thrift-client/src/main/connections/HttpConnection.ts @@ -207,14 +207,20 @@ export class HttpConnection extends ThriftConnection { if (shouldRetry(response, retry, this.withEndpointPerMethod)) { resolve(this.write(dataToWrite, methodName, options, true)) } else if (isErrorResponse(response)) { - reject( - new ThriftRequestError( - `Thrift request failed: HTTP ${response.status} ${ - response.statusText - }: ${response.text()}`, - response + const baseMessage = `Thrift request failed: HTTP ${response.status} ${response.statusText}` + response + .text() + .then(responseText => + reject(new ThriftRequestError(`${baseMessage}: ${responseText}`, response)) ) - ) + .catch(reason => { + reject( + new ThriftRequestError( + `${baseMessage} and the response body could not be read: ${reason}`, + response + ) + ) + }) } else { response.arrayBuffer().then(arrayBuffer => resolve({