diff --git a/packages/superagent-wrapper/src/request.ts b/packages/superagent-wrapper/src/request.ts index 9564bd3c..c86bfdd7 100644 --- a/packages/superagent-wrapper/src/request.ts +++ b/packages/superagent-wrapper/src/request.ts @@ -53,6 +53,7 @@ type SuperagentLike = { export type Response = { body: unknown; + text: unknown; status: number; }; @@ -126,23 +127,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), ), @@ -151,7 +153,7 @@ const patchRequest = < decodedResponse({ status: 'decodeError', error: PathReporter.failure(error).join('\n'), - body: res.body, + body: bodyOrText, original: res, }), ),