Skip to content

Commit 7a55dde

Browse files
Added more detailed debugging.
1 parent 8a19cc4 commit 7a55dde

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

utils/location.utils.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ export const reverseGeocode = async (
5252
/**
5353
* Save the user's location to the backend API.
5454
*/
55-
5655
export const saveLocation = async (
5756
location: LocationLibrary.LocationObject,
5857
geoAddress: LocationLibrary.LocationGeocodedAddress,
59-
token: string | null // Add token parameter
58+
token: string | null
6059
): Promise<void> => {
6160
if (!token) {
6261
console.log("No FCM token available; skipping save location.");
@@ -67,10 +66,9 @@ export const saveLocation = async (
6766

6867
try {
6968
const payload = {
70-
subscriptionId: token, // Use the passed token
69+
subscriptionId: token,
7170
latitude: location.coords.latitude,
7271
longitude: location.coords.longitude,
73-
// ... (rest of the payload remains the same)
7472
};
7573

7674
const response = await fetch("https://new.codebuilder.org/api/location", {
@@ -79,12 +77,18 @@ export const saveLocation = async (
7977
body: JSON.stringify(payload),
8078
});
8179

80+
const responseBody = await response.text(); // Always try to read the body, even if it's empty
81+
8282
if (!response.ok) {
83-
throw new Error(`Error saving location: ${response.statusText}`);
83+
throw new Error(
84+
`HTTP ${response.status}: ${response.statusText}\nResponse Body: ${
85+
responseBody || "No content"
86+
}`
87+
);
8488
}
8589

8690
console.log("Location and address saved to server successfully.");
87-
} catch (error) {
88-
console.error("Error saving location to server:", error);
91+
} catch (error: any) {
92+
console.error("Error saving location to server:", error?.message || error);
8993
}
9094
};

0 commit comments

Comments
 (0)