laravel-request 1.1.49 → 1.2.2
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/Api.js +10 -3
- package/src/ApiRequest.js +4 -4
package/package.json
CHANGED
package/src/Api.js
CHANGED
|
@@ -192,7 +192,14 @@ export default class Api {
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
|
|
195
|
+
/**
|
|
196
|
+
*
|
|
197
|
+
* @param url
|
|
198
|
+
* @param response
|
|
199
|
+
* @param contentType
|
|
200
|
+
* @returns {Promise<*|string>}
|
|
201
|
+
*/
|
|
202
|
+
static async decodeResponse(url, response, contentType) {
|
|
196
203
|
try {
|
|
197
204
|
if (contentType.includes("application/msgpack")) {
|
|
198
205
|
// Декодирование MessagePack
|
|
@@ -271,7 +278,7 @@ export default class Api {
|
|
|
271
278
|
throw new Error("Missing Content-Type header in the response");
|
|
272
279
|
}
|
|
273
280
|
|
|
274
|
-
const responseData = await Api.decodeResponse(response, contentType);
|
|
281
|
+
const responseData = await Api.decodeResponse(url, response, contentType);
|
|
275
282
|
const statusCode = response.status;
|
|
276
283
|
const xhr = response.request;
|
|
277
284
|
|
|
@@ -293,7 +300,7 @@ export default class Api {
|
|
|
293
300
|
const xhr = response.request;
|
|
294
301
|
|
|
295
302
|
const contentType = response.headers.get("Content-Type");
|
|
296
|
-
const responseData = await Api.decodeResponse(response, contentType);
|
|
303
|
+
const responseData = await Api.decodeResponse(url, response, contentType);
|
|
297
304
|
|
|
298
305
|
const statusCode = response.status;
|
|
299
306
|
const statusText = response.statusText;
|
package/src/ApiRequest.js
CHANGED
|
@@ -238,7 +238,7 @@ export default class ApiRequest {
|
|
|
238
238
|
// handle 404 specifically if needed
|
|
239
239
|
break;
|
|
240
240
|
default:
|
|
241
|
-
notify = this.defaultErrorMessage(
|
|
241
|
+
notify = this.defaultErrorMessage(responseData, errorText);
|
|
242
242
|
}
|
|
243
243
|
} else if (response.readyState === 0) {
|
|
244
244
|
notify = this.getNotifyManager().errorOnce('network_error', 'Ошибка', ' (Network Error) или невозможность получения доступа к сети');
|
|
@@ -368,7 +368,7 @@ export default class ApiRequest {
|
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
this.toBindErrors(responseData);
|
|
371
|
-
errorCallback(response);
|
|
371
|
+
errorCallback(response, responseData);
|
|
372
372
|
}
|
|
373
373
|
|
|
374
374
|
/**
|
|
@@ -459,9 +459,9 @@ export default class ApiRequest {
|
|
|
459
459
|
*/
|
|
460
460
|
toBindErrors(responseData = {})
|
|
461
461
|
{
|
|
462
|
-
if (responseData && typeof responseData === 'object' && responseData?.meta?.errors)
|
|
462
|
+
if (this?.responseBindingErrors && responseData && typeof responseData === 'object' && responseData?.meta?.errors)
|
|
463
463
|
{
|
|
464
|
-
this.responseBindingErrors
|
|
464
|
+
this.responseBindingErrors?.fire(responseData.meta.errors);
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
467
|
|