MCPcopy
hub / github.com/spaceandtimefdn/SxT-NodeJS-SDK / QueryHelper

Function QueryHelper

src/helpers/queryhelper.ts:4–42  ·  view source on GitHub ↗
(
    options: Types.Options,
    httpOk: number = 0
)

Source from the content-addressed store, hash-verified

2import * as Types from "./types.js";
3
4export const QueryHelper = async (
5 options: Types.Options,
6 httpOk: number = 0
7): Promise<Types.APIResponse> => {
8 let output: Types.APIResponse = {};
9 try {
10 const result = await axios.request(options);
11 if (httpOk <= 0) {
12 output = {
13 error: new Error(`No default http ok condition specified`),
14 };
15 } else {
16 switch (httpOk) {
17 case 200:
18 output = {
19 data: result.data,
20 };
21 break;
22 case 204:
23 output = {
24 data: null,
25 };
26 break;
27 default:
28 output = {
29 error: new Error(`Bad http ok condition`),
30 };
31 }
32 }
33 } catch (err: any) {
34 output = {
35 error: new Error(
36 `${err.response.status}: ${err.response.data.title}. Detail: ${err.response.data.detail}`
37 ),
38 };
39 }
40
41 return output;
42};

Callers 3

AuthenticationClass · 0.85
SQLCoreClass · 0.85
DiscoveryAPIClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected