Skip to content

Commit c75b51b

Browse files
Merge pull request #1047 from ericcrosson-bitgo/add-support-for-text-in-response
add support for text in response
2 parents a203328 + f626d91 commit c75b51b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/superagent-wrapper/src/request.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type SuperagentLike<Req> = {
5353

5454
export type Response = {
5555
body: unknown;
56+
text: unknown;
5657
status: number;
5758
};
5859

@@ -126,19 +127,20 @@ const patchRequest = <
126127

127128
patchedReq.decode = () =>
128129
req.then((res) => {
129-
const { body, status } = res;
130+
const { body, text, status } = res;
131+
const bodyOrText = body || text;
130132

131133
if (!hasCodecForStatus(route.response, status)) {
132134
return decodedResponse({
133135
// DISCUSS: what's this non-standard HTTP status code?
134136
status: 'decodeError',
135137
error: `No codec for status ${status}`,
136-
body,
138+
body: bodyOrText,
137139
original: res,
138140
});
139141
}
140142
return pipe(
141-
route.response[status].decode(res.body),
143+
route.response[status].decode(bodyOrText),
142144
E.map((body) =>
143145
decodedResponse<Route>({
144146
status,
@@ -151,7 +153,7 @@ const patchRequest = <
151153
decodedResponse<Route>({
152154
status: 'decodeError',
153155
error: PathReporter.failure(error).join('\n'),
154-
body: res.body,
156+
body: bodyOrText,
155157
original: res,
156158
}),
157159
),

0 commit comments

Comments
 (0)