atom-nuxt 1.0.148 → 1.0.149
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/module.json
CHANGED
|
@@ -82,42 +82,37 @@ export const useCrudApi = (path, watchPage = true, transformItem = null, transfo
|
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
if (atomNuxtConfig.debug) {
|
|
85
|
-
console.log("Request:", {
|
|
86
|
-
url,
|
|
87
|
-
options
|
|
88
|
-
});
|
|
85
|
+
console.log("Request:", { url, options });
|
|
89
86
|
}
|
|
90
|
-
const response = await fetch(url,
|
|
87
|
+
const response = await $fetch.raw(url, {
|
|
88
|
+
method: options.method,
|
|
89
|
+
headers: options.headers,
|
|
90
|
+
body: options.body,
|
|
91
|
+
baseURL: atomNuxtConfig.apiBaseUrl
|
|
92
|
+
// SSR-safe
|
|
93
|
+
});
|
|
91
94
|
if (atomNuxtConfig.debug) {
|
|
92
95
|
console.log("Response Status:", response.status, response.statusText);
|
|
93
96
|
console.log("Response Headers:", [...response.headers.entries()]);
|
|
94
97
|
}
|
|
95
98
|
if (!response.ok) {
|
|
96
|
-
console.log("Response Failed with status:", response.status);
|
|
97
99
|
if (response.status === 401 && crudOnUnauthenticated) {
|
|
98
100
|
await crudOnUnauthenticated();
|
|
99
101
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
let errorBody;
|
|
103
|
+
try {
|
|
104
|
+
errorBody = response._data;
|
|
105
|
+
} catch {
|
|
106
|
+
errorBody = null;
|
|
102
107
|
}
|
|
103
|
-
const errorBody = await response.json().catch(() => null);
|
|
104
108
|
errors.value = errorBody || { message: "Failed to parse error response" };
|
|
105
109
|
throw new FetchError(response.statusText, response.status);
|
|
106
110
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const contentType = response.headers.get("content-type");
|
|
111
|
-
let responseBody;
|
|
112
|
-
if (contentType && contentType.includes("application/json")) {
|
|
113
|
-
responseBody = await response.json();
|
|
114
|
-
} else {
|
|
115
|
-
responseBody = await response.text();
|
|
116
|
-
}
|
|
117
|
-
if (response.headers.get("user-message")) {
|
|
118
|
-
setAlertMessage(response.headers.get("user-message"));
|
|
111
|
+
const userMessage = response.headers.get("user-message");
|
|
112
|
+
if (userMessage) {
|
|
113
|
+
setAlertMessage(userMessage);
|
|
119
114
|
}
|
|
120
|
-
return
|
|
115
|
+
return response._data;
|
|
121
116
|
} catch (error) {
|
|
122
117
|
if (error.status === 401 && crudOnUnauthenticated) {
|
|
123
118
|
await crudOnUnauthenticated();
|
|
@@ -125,6 +120,7 @@ export const useCrudApi = (path, watchPage = true, transformItem = null, transfo
|
|
|
125
120
|
if (atomNuxtConfig.debug) {
|
|
126
121
|
console.error("Request error:", error);
|
|
127
122
|
}
|
|
123
|
+
throw error;
|
|
128
124
|
} finally {
|
|
129
125
|
pending.value = false;
|
|
130
126
|
}
|