From b6791a5a6eaa39842f1c9f2f4d72716841a2a39e Mon Sep 17 00:00:00 2001 From: Piotr Frankowski Date: Thu, 8 Dec 2022 00:02:34 +0100 Subject: [PATCH] add support for text in response --- packages/superagent-wrapper/src/request.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/superagent-wrapper/src/request.ts b/packages/superagent-wrapper/src/request.ts index c2047c29..89d0f39c 100644 --- a/packages/superagent-wrapper/src/request.ts +++ b/packages/superagent-wrapper/src/request.ts @@ -52,6 +52,7 @@ type SuperagentLike = { type Response = { body: unknown; + text: unknown; status: number; }; @@ -124,23 +125,24 @@ const patchRequest = < patchedReq.decode = () => req.then((res) => { - const { body, status } = res; + const { body, text, status } = res; + const bodyOrText = body || text; if (!hasCodecForStatus(route.response, status)) { return decodedResponse({ // DISCUSS: what's this non-standard HTTP status code? status: 'decodeError', error: `No codec for status ${status}`, - body, + body: bodyOrText, original: res, }); } return pipe( - route.response[status].decode(res.body), + route.response[status].decode(bodyOrText), E.map((body) => decodedResponse({ status, - body, + body: bodyOrText, original: res, } as SuccessfulResponses), ), @@ -149,7 +151,7 @@ const patchRequest = < decodedResponse({ status: 'decodeError', error: PathReporter.failure(error).join('\n'), - body: res.body, + body: bodyOrText, original: res, }), ),