MCPcopy
hub / github.com/msgbyte/tianji / getResponseBody

Function getResponseBody

packages/client-sdk/src/open/client/core/request.ts:210–231  ·  view source on GitHub ↗
(response: Response)

Source from the content-addressed store, hash-verified

208};
209
210export const getResponseBody = async (response: Response): Promise<unknown> => {
211 if (response.status !== 204) {
212 try {
213 const contentType = response.headers.get('Content-Type');
214 if (contentType) {
215 const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/'];
216 if (contentType.includes('application/json') || contentType.includes('+json')) {
217 return await response.json();
218 } else if (binaryTypes.some(type => contentType.includes(type))) {
219 return await response.blob();
220 } else if (contentType.includes('multipart/form-data')) {
221 return await response.formData();
222 } else if (contentType.includes('text/')) {
223 return await response.text();
224 }
225 }
226 } catch (error) {
227 console.error(error);
228 }
229 }
230 return undefined;
231};
232
233export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
234 const errors: Record<number, string> = {

Callers 1

requestFunction · 0.85

Calls 5

blobMethod · 0.80
errorMethod · 0.80
getMethod · 0.65
jsonMethod · 0.65
textMethod · 0.65

Tested by

no test coverage detected