Skip to content

Commit 140d2b4

Browse files
piotrfrankowskiericcrosson-bitgo
authored andcommitted
add support for text in response
1 parent a203328 commit 140d2b4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

packages/superagent-wrapper/src/request.ts

Lines changed: 7 additions & 5 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,23 +127,24 @@ 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,
145-
body,
147+
body: bodyOrText,
146148
original: res,
147149
} as SuccessfulResponses<Route>),
148150
),
@@ -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)