hosting: fix notification on reserve
This commit is contained in:
@@ -28,14 +28,12 @@ const useFetchHosting = () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const response = await fetch('https://example.backend.com/hosting');
|
||||
if (!response.ok) {
|
||||
const response = await fetch('/hosting');
|
||||
if (response.status != 200) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
const result = await response.json();
|
||||
setData(result);
|
||||
} catch (error) {
|
||||
setError(error instanceof Error ? error.message : 'Unknown error');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -45,7 +43,7 @@ const useFetchHosting = () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const response = await fetch(`https://example.backend.com/hosting/${id}`, {
|
||||
const response = await fetch(`/hosting/${id}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -53,19 +51,19 @@ const useFetchHosting = () => {
|
||||
body: JSON.stringify({ reservedBy: name })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
if (!response.ok) { // Check for non-200 responses
|
||||
const errorText = await response.text(); // Capture the response text for further insights
|
||||
throw new Error(`Error ${response.status}: ${errorText}`);
|
||||
}
|
||||
|
||||
// Optional: Fetch the updated data after reservation
|
||||
await fetchData();
|
||||
} catch (error) {
|
||||
setError(error instanceof Error ? error.message : 'Unknown error');
|
||||
await fetchData();
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
//fetchData(); // Initial fetch on mount
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user