-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfetchCommands.ts
More file actions
49 lines (46 loc) · 1.44 KB
/
Copy pathfetchCommands.ts
File metadata and controls
49 lines (46 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// @ts-ignore
import { fetchWithErrorHandling } from '@neos-project/neos-ui-backend-connector';
import { CommandList } from '../interfaces';
import logToConsole from './logger';
const fetchCommands = async (endPoint: string): Promise<{ success: boolean; result: CommandList }> => {
return fetchWithErrorHandling
.withCsrfToken((csrfToken: string) => ({
url: endPoint,
method: 'GET',
credentials: 'include',
headers: {
'X-Flow-Csrftoken': csrfToken,
'Content-Type': 'application/json',
},
}))
.then((response: Response) => {
if (!response.ok) {
return {
success: false,
result: {},
};
}
return (
response &&
response
.json()
.then((data: CommandList) => {
return data;
})
.catch(() => {
return {
success: false,
result: {},
};
})
);
})
.catch((error: Error) => {
logToConsole('error', error.message);
return {
success: false,
result: {},
};
});
};
export default fetchCommands;