@dvrd/dvr-controls 1.0.51 → 1.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/js/util/requestUtil.ts +11 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dvrd/dvr-controls",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.52",
|
|
4
4
|
"description": "Custom web controls",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"files": [
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"react-router-dom": "6.15.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@dvrd/idate": "^1.
|
|
33
|
+
"@dvrd/idate": "^1.8.1",
|
|
34
34
|
"@fortawesome/fontawesome-svg-core": "6.3.0",
|
|
35
35
|
"@fortawesome/free-brands-svg-icons": "6.3.0",
|
|
36
36
|
"@fortawesome/free-regular-svg-icons": "6.3.0",
|
|
@@ -19,7 +19,7 @@ export interface FetchOptions {
|
|
|
19
19
|
data?: {};
|
|
20
20
|
stringifyData?: boolean;
|
|
21
21
|
headers?: OutgoingHttpHeaders;
|
|
22
|
-
callback?:
|
|
22
|
+
callback?: (data: ResponseData, response: Response) => void;
|
|
23
23
|
errorCallback?: (response: Response | string) => void;
|
|
24
24
|
credentials?: string;
|
|
25
25
|
responseParser?: ResponseHandler;
|
|
@@ -67,11 +67,11 @@ function bigIntParser(_: string, value: any) {
|
|
|
67
67
|
return value;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
export function sendFetch(config: FetchOptions
|
|
70
|
+
export function sendFetch(config: FetchOptions): AbortController | null {
|
|
71
71
|
const baseUrl = config.baseUrl || window.settings.platformUrl;
|
|
72
72
|
if (!baseUrl) throw new Error('Base url is not set!');
|
|
73
73
|
|
|
74
|
-
config = _prepareConfig(config
|
|
74
|
+
config = _prepareConfig(config);
|
|
75
75
|
const {url, method, headers, data} = config;
|
|
76
76
|
const options: { [index: string]: any } = {
|
|
77
77
|
headers,
|
|
@@ -106,13 +106,13 @@ function _handleResponse(response: Response, config: FetchOptions) {
|
|
|
106
106
|
if (data.message === 'Invalid rights') {
|
|
107
107
|
showDialog('Je hebt niet genoeg rechten voor deze actie.');
|
|
108
108
|
data.handled = true;
|
|
109
|
-
if (config.callback) config.callback(data);
|
|
109
|
+
if (config.callback) config.callback(data, response);
|
|
110
110
|
} else if (config.callback) {
|
|
111
111
|
data.success = responseDataIsSuccess(data);
|
|
112
|
-
config.callback(data);
|
|
112
|
+
config.callback(data, response);
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
|
-
} else config.callback(response);
|
|
115
|
+
} else config.callback({status: 'success'}, response);
|
|
116
116
|
} else
|
|
117
117
|
_onErrorResponse(response, config);
|
|
118
118
|
}
|
|
@@ -121,10 +121,13 @@ function _onErrorResponse(response: Response, config: FetchOptions) {
|
|
|
121
121
|
if (config.errorHandler) config.errorHandler(response, config);
|
|
122
122
|
else if (config.errorCallback) config.errorCallback(response);
|
|
123
123
|
else if (defaultErrorHandler) defaultErrorHandler(response, config);
|
|
124
|
-
else if (config.callback) config.callback({
|
|
124
|
+
else if (config.callback) config.callback({
|
|
125
|
+
status: 'error',
|
|
126
|
+
message: 'Er is iets misgegaan in het systeem.'
|
|
127
|
+
}, response);
|
|
125
128
|
}
|
|
126
129
|
|
|
127
|
-
function _prepareConfig(options: FetchOptions
|
|
130
|
+
function _prepareConfig(options: FetchOptions): FetchOptions {
|
|
128
131
|
const fetchOptions: FetchOptions = Object.assign({}, options);
|
|
129
132
|
if (!fetchOptions.method) fetchOptions.method = FetchMethod.GET;
|
|
130
133
|
if (!fetchOptions.callback) fetchOptions.callback = voidFunction;
|
|
@@ -135,13 +138,6 @@ function _prepareConfig(options: FetchOptions, legacySupport: boolean = true): F
|
|
|
135
138
|
warn('Cannot send data with GET requests, data will be ignored.');
|
|
136
139
|
|
|
137
140
|
if (fetchOptions.credentials === undefined) fetchOptions.credentials = 'same-origin';
|
|
138
|
-
|
|
139
|
-
if (legacySupport && fetchOptions.callback) {
|
|
140
|
-
const legacyCallback = fetchOptions.callback;
|
|
141
|
-
fetchOptions.callback = (data: ResponseData) => {
|
|
142
|
-
legacyCallback({data});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
141
|
return setAuthHeader(fetchOptions);
|
|
146
142
|
}
|
|
147
143
|
|