@radiantabyss/vue 3.3.16 → 3.3.18
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 +1 -1
- package/src/Request.js +16 -9
package/package.json
CHANGED
package/src/Request.js
CHANGED
|
@@ -88,20 +88,27 @@ const buildParams = (obj, prefix = '', params = new URLSearchParams()) => {
|
|
|
88
88
|
return params;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
//recursively
|
|
92
|
-
|
|
91
|
+
//recursively drop undefined values; null is dropped too, or sent as an empty string when null_as_empty
|
|
92
|
+
//is set (form bodies can't carry null, and `key=` lets the backend read it as null to clear a field)
|
|
93
|
+
const cleanPayload = (value, null_as_empty) => {
|
|
94
|
+
const isDropped = (v) => v === undefined || (v === null && !null_as_empty);
|
|
95
|
+
|
|
96
|
+
if ( value === null ) {
|
|
97
|
+
return null_as_empty ? '' : value;
|
|
98
|
+
}
|
|
99
|
+
|
|
93
100
|
if ( Array.isArray(value) ) {
|
|
94
|
-
return value.map(
|
|
101
|
+
return value.filter((v) => !isDropped(v)).map((v) => cleanPayload(v, null_as_empty));
|
|
95
102
|
}
|
|
96
103
|
|
|
97
|
-
if (
|
|
104
|
+
if ( typeof value === 'object' && !(value instanceof Blob) ) {
|
|
98
105
|
const cleaned = {};
|
|
99
106
|
for ( let key in value ) {
|
|
100
|
-
if ( value[key]
|
|
107
|
+
if ( isDropped(value[key]) ) {
|
|
101
108
|
continue;
|
|
102
109
|
}
|
|
103
110
|
|
|
104
|
-
cleaned[key] =
|
|
111
|
+
cleaned[key] = cleanPayload(value[key], null_as_empty);
|
|
105
112
|
}
|
|
106
113
|
|
|
107
114
|
return cleaned;
|
|
@@ -170,8 +177,8 @@ const request = function(method, edge, payload = {}, display_errors = false, bas
|
|
|
170
177
|
current[edge] = _cancel;
|
|
171
178
|
}
|
|
172
179
|
|
|
173
|
-
//drop undefined
|
|
174
|
-
payload =
|
|
180
|
+
//drop undefined keys; GET drops null too, POST sends it as an empty value
|
|
181
|
+
payload = cleanPayload(payload, method != 'GET');
|
|
175
182
|
|
|
176
183
|
let data;
|
|
177
184
|
let url = base_url + edge;
|
|
@@ -273,7 +280,7 @@ const request = function(method, edge, payload = {}, display_errors = false, bas
|
|
|
273
280
|
let errors = [error.message];
|
|
274
281
|
|
|
275
282
|
if ( display_errors ) {
|
|
276
|
-
Alert.error(
|
|
283
|
+
Alert.error(__('Internal Server Error. We\'re fixing the problem. Please retry in a couple of hours.'), 7000);
|
|
277
284
|
}
|
|
278
285
|
|
|
279
286
|
if ( _button !== undefined ) {
|