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