MCPcopy Create free account
hub / github.com/decaporg/decap-cms / parseResponse

Function parseResponse

packages/decap-cms-lib-util/src/backendUtil.ts:43–63  ·  view source on GitHub ↗
(
  res: Response,
  { expectingOk = true, format = 'text', apiName = '' },
)

Source from the content-addressed store, hash-verified

41]);
42
43export async function parseResponse(
44 res: Response,
45 { expectingOk = true, format = 'text', apiName = '' },
46) {
47 let body;
48 try {
49 const formatter = responseFormatters.get(format, false);
50 if (!formatter) {
51 throw new Error(`${format} is not a supported response format.`);
52 }
53 body = await formatter(res);
54 } catch (err) {
55 throw new APIError(err.message, res.status, apiName);
56 }
57 if (expectingOk && !res.ok) {
58 const isJSON = format === 'json';
59 const message = isJSON ? body.message || body.msg || body.error?.message : body;
60 throw new APIError(isJSON && message ? message : body, res.status, apiName);
61 }
62 return body;
63}
64
65export function responseParser(options: {
66 expectingOk?: boolean;

Callers 1

responseParserFunction · 0.70

Calls 1

getMethod · 0.80

Tested by

no test coverage detected