@@ -52,11 +52,10 @@ export const reverseGeocode = async (
52
52
/**
53
53
* Save the user's location to the backend API.
54
54
*/
55
-
56
55
export const saveLocation = async (
57
56
location : LocationLibrary . LocationObject ,
58
57
geoAddress : LocationLibrary . LocationGeocodedAddress ,
59
- token : string | null // Add token parameter
58
+ token : string | null
60
59
) : Promise < void > => {
61
60
if ( ! token ) {
62
61
console . log ( "No FCM token available; skipping save location." ) ;
@@ -67,10 +66,9 @@ export const saveLocation = async (
67
66
68
67
try {
69
68
const payload = {
70
- subscriptionId : token , // Use the passed token
69
+ subscriptionId : token ,
71
70
latitude : location . coords . latitude ,
72
71
longitude : location . coords . longitude ,
73
- // ... (rest of the payload remains the same)
74
72
} ;
75
73
76
74
const response = await fetch ( "https://new.codebuilder.org/api/location" , {
@@ -79,12 +77,18 @@ export const saveLocation = async (
79
77
body : JSON . stringify ( payload ) ,
80
78
} ) ;
81
79
80
+ const responseBody = await response . text ( ) ; // Always try to read the body, even if it's empty
81
+
82
82
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
+ ) ;
84
88
}
85
89
86
90
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 ) ;
89
93
}
90
94
} ;
0 commit comments