MCPcopy Create free account
hub / github.com/alibaba/lowcode-engine / request

Function request

packages/editor-core/src/utils/request.ts:51–128  ·  view source on GitHub ↗
(
  dataAPI: string,
  method = 'GET',
  data?: object | string,
  headers?: object,
  otherProps?: any,
)

Source from the content-addressed store, hash-verified

49}
50
51export function request(
52 dataAPI: string,
53 method = 'GET',
54 data?: object | string,
55 headers?: object,
56 otherProps?: any,
57): Promise<any> {
58 return new Promise((resolve, reject): void => {
59 if (otherProps && otherProps.timeout) {
60 setTimeout((): void => {
61 reject(new Error('timeout'));
62 }, otherProps.timeout);
63 }
64 fetch(dataAPI, {
65 method,
66 credentials: 'include',
67 headers,
68 body: data,
69 ...otherProps,
70 })
71 .then((response: Response): any => {
72 switch (response.status) {
73 case 200:
74 case 201:
75 case 202:
76 return response.json();
77 case 204:
78 if (method === 'DELETE') {
79 return {
80 success: true,
81 };
82 } else {
83 return {
84 __success: false,
85 code: response.status,
86 };
87 }
88 case 400:
89 case 401:
90 case 403:
91 case 404:
92 case 406:
93 case 410:
94 case 422:
95 case 500:
96 return response
97 .json()
98 .then((res: object): any => {
99 return {
100 __success: false,
101 code: response.status,
102 data: res,
103 };
104 })
105 .catch((): object => {
106 return {
107 __success: false,
108 code: response.status,

Callers 2

getFunction · 0.70
postFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…