@inertiajs/core 3.0.0-beta.1 → 3.0.0-beta.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/dist/index.js +30 -9
- package/dist/index.js.map +3 -3
- package/package.json +2 -2
- package/types/axiosHttpClient.d.ts +1 -4
- package/types/response.d.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -2217,6 +2217,18 @@ var Response = class _Response {
|
|
|
2217
2217
|
if (!this.isInertiaResponse()) {
|
|
2218
2218
|
return this.handleNonInertiaResponse();
|
|
2219
2219
|
}
|
|
2220
|
+
if (this.isHttpException()) {
|
|
2221
|
+
const response = {
|
|
2222
|
+
...this.response,
|
|
2223
|
+
data: this.getDataFromResponse(this.response.data)
|
|
2224
|
+
};
|
|
2225
|
+
if (this.requestParams.all().onHttpException(response) === false) {
|
|
2226
|
+
return;
|
|
2227
|
+
}
|
|
2228
|
+
if (!fireHttpExceptionEvent(response)) {
|
|
2229
|
+
return;
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2220
2232
|
await history.processQueue();
|
|
2221
2233
|
history.preserveUrl = this.requestParams.all().preserveUrl;
|
|
2222
2234
|
const previousFlash = page.get().flash;
|
|
@@ -2278,6 +2290,9 @@ var Response = class _Response {
|
|
|
2278
2290
|
isInertiaResponse() {
|
|
2279
2291
|
return this.hasHeader("x-inertia");
|
|
2280
2292
|
}
|
|
2293
|
+
isHttpException() {
|
|
2294
|
+
return this.response.status >= 400;
|
|
2295
|
+
}
|
|
2281
2296
|
hasStatus(status2) {
|
|
2282
2297
|
return this.response.status === status2;
|
|
2283
2298
|
}
|
|
@@ -3354,7 +3369,6 @@ var UseFormUtils = class {
|
|
|
3354
3369
|
};
|
|
3355
3370
|
|
|
3356
3371
|
// src/axiosHttpClient.ts
|
|
3357
|
-
import axios from "axios";
|
|
3358
3372
|
function normalizeHeaders(headers) {
|
|
3359
3373
|
if (!headers || typeof headers !== "object") {
|
|
3360
3374
|
return {};
|
|
@@ -3377,15 +3391,22 @@ function toHttpProgressEvent(axiosEvent) {
|
|
|
3377
3391
|
total: axiosEvent.total
|
|
3378
3392
|
};
|
|
3379
3393
|
}
|
|
3394
|
+
var axiosModulePromise;
|
|
3395
|
+
function loadAxiosModule() {
|
|
3396
|
+
if (!axiosModulePromise) {
|
|
3397
|
+
axiosModulePromise = import("axios").catch((error) => {
|
|
3398
|
+
axiosModulePromise = void 0;
|
|
3399
|
+
throw error;
|
|
3400
|
+
});
|
|
3401
|
+
}
|
|
3402
|
+
return axiosModulePromise;
|
|
3403
|
+
}
|
|
3380
3404
|
var AxiosHttpClient = class {
|
|
3381
3405
|
constructor(instance) {
|
|
3382
|
-
this.
|
|
3406
|
+
this.axiosInstance = instance ? Promise.resolve(instance) : loadAxiosModule().then((module) => module.default);
|
|
3383
3407
|
}
|
|
3384
3408
|
async getAxios() {
|
|
3385
|
-
|
|
3386
|
-
return this.axios = axios;
|
|
3387
|
-
}
|
|
3388
|
-
return this.axios;
|
|
3409
|
+
return this.axiosInstance;
|
|
3389
3410
|
}
|
|
3390
3411
|
async request(config2) {
|
|
3391
3412
|
const processedConfig = await httpHandlers.processRequest(config2);
|
|
@@ -3400,9 +3421,9 @@ var AxiosHttpClient = class {
|
|
|
3400
3421
|
}
|
|
3401
3422
|
}
|
|
3402
3423
|
async doRequest(config2) {
|
|
3403
|
-
const
|
|
3424
|
+
const axios = await this.getAxios();
|
|
3404
3425
|
try {
|
|
3405
|
-
const response = await
|
|
3426
|
+
const response = await axios({
|
|
3406
3427
|
method: config2.method,
|
|
3407
3428
|
url: config2.url,
|
|
3408
3429
|
data: config2.data,
|
|
@@ -3418,7 +3439,7 @@ var AxiosHttpClient = class {
|
|
|
3418
3439
|
headers: normalizeHeaders(response.headers)
|
|
3419
3440
|
};
|
|
3420
3441
|
} catch (error) {
|
|
3421
|
-
const axiosModule = await
|
|
3442
|
+
const axiosModule = await loadAxiosModule();
|
|
3422
3443
|
if (axiosModule.default.isCancel(error)) {
|
|
3423
3444
|
throw new HttpCancelledError("Request was cancelled", config2.url);
|
|
3424
3445
|
}
|