diff --git a/backend/db/app_location.go b/backend/db/app_location.go index 97f39fe..3e6d1cb 100644 --- a/backend/db/app_location.go +++ b/backend/db/app_location.go @@ -583,7 +583,7 @@ func (a *AppDB) AddLocation(ctx context.Context, location *structs.Location) err $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32 ) - ON CONFLICT (google_id) WHERE active = TRUE + ON CONFLICT (google_id) WHERE active = TRUE AND google_id IS NOT NULL DO UPDATE SET owner_id = EXCLUDED.owner_id, name = EXCLUDED.name, diff --git a/backend/handlers/app_location.go b/backend/handlers/app_location.go index fa4348d..8944453 100644 --- a/backend/handlers/app_location.go +++ b/backend/handlers/app_location.go @@ -145,8 +145,8 @@ func (a *AppService) AddLocation(w http.ResponseWriter, r *http.Request) { location.OwnerID = *userDid err = a.db.AddLocation(r.Context(), location) if err != nil { - w.WriteHeader(http.StatusBadRequest) a.logger.Logf("invalid location body: %s", err.Error()) + http.Error(w, "Unable to submit merchant application.", http.StatusBadRequest) return } diff --git a/frontend/components/merchant/merchant-approval-form.tsx b/frontend/components/merchant/merchant-approval-form.tsx index be1ab2e..b2a7d2a 100644 --- a/frontend/components/merchant/merchant-approval-form.tsx +++ b/frontend/components/merchant/merchant-approval-form.tsx @@ -190,15 +190,22 @@ export function MerchantApprovalForm() { service_stations: Number(serviceStations), tablet_model: tabletModel === "Other" ? tabletModelOther : tabletModel, messaging_service: messagingService === "Other" ? messagingServiceOther : messagingService, + payment_wallets: [], reference: reference, } setIsSubmitting(true) - await addLocation(newLocation) - setSearchKey(prev => prev + 1) - setIsSubmitting(false); - resetForm() - router.replace("/map") + setError(null) + try { + await addLocation(newLocation) + setSearchKey(prev => prev + 1) + resetForm() + router.replace("/map") + } catch (error) { + setError(error instanceof Error ? error.message : "Unable to submit merchant application.") + } finally { + setIsSubmitting(false) + } } return ( diff --git a/frontend/context/LocationProvider.tsx b/frontend/context/LocationProvider.tsx index e3aa193..4d6cba7 100644 --- a/frontend/context/LocationProvider.tsx +++ b/frontend/context/LocationProvider.tsx @@ -132,14 +132,16 @@ export default function LocationProvider({ children }: { children: ReactNode }) body: JSON.stringify(location) }) if(res.status != 201) { - throw new Error("error adding new location, from controller") + const message = (await res.text()).trim() + throw new Error(message || "Unable to submit merchant application.") } setUserLocationsRef.current((currentLocations) => [...currentLocations, location]) setMapLocationsStatus("available") } - catch { + catch (error) { setMapLocationsStatus("unavailable") - console.error("error adding new location") + console.error("error adding new location", error) + throw error } }, [])