MCPcopy Index your code
hub / github.com/Dispatcharr/Dispatcharr / request

Function request

frontend/src/api.js:53–99  ·  view source on GitHub ↗
(url, options = {})

Source from the content-addressed store, hash-verified

51};
52
53const request = async (url, options = {}) => {
54 if (
55 options.body &&
56 !(options.body instanceof FormData) &&
57 typeof options.body === 'object'
58 ) {
59 options.body = JSON.stringify(options.body);
60 options.headers = {
61 ...options.headers,
62 'Content-Type': 'application/json',
63 };
64 }
65
66 if (options.auth !== false) {
67 options.headers = {
68 ...options.headers,
69 Authorization: `Bearer ${await API.getAuthToken()}`,
70 };
71 }
72
73 const response = await fetch(url, options);
74
75 if (!response.ok) {
76 const error = new Error(`HTTP error! Status: ${response.status}`);
77
78 let errorBody = await response.text();
79
80 try {
81 errorBody = JSON.parse(errorBody);
82 } catch (e) {
83 // If parsing fails, leave errorBody as the raw text
84 }
85
86 error.status = response.status;
87 error.response = response;
88 error.body = errorBody;
89
90 throw error;
91 }
92
93 try {
94 const retval = await response.json();
95 return retval;
96 } catch (e) {
97 return '';
98 }
99};
100
101export default class API {
102 static lastQueryParams = new URLSearchParams();

Callers 15

fetchAllByCountMethod · 0.85
fetchSuperUserMethod · 0.85
createSuperUserMethod · 0.85
loginMethod · 0.85
refreshTokenMethod · 0.85
logoutMethod · 0.85
getChannelsMethod · 0.85
getChannelsSummaryMethod · 0.85
repackGroupChannelsMethod · 0.85
getChannelsInRangeMethod · 0.85
queryChannelsMethod · 0.85

Calls 2

getAuthTokenMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected