Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

add error logging

Abhinav3d72e58c558d
diff --git a/apps/photos/src/services/locationSearchService.ts b/apps/photos/src/services/locationSearchService.ts
index c3d63db782..eebe44fac8 100644
--- a/apps/photos/src/services/locationSearchService.ts
+++ b/apps/photos/src/services/locationSearchService.ts
@@ -1,4 +1,5 @@
import { CITIES_URL } from '@ente/shared/constants/urls';
+import { logError } from '@ente/shared/sentry';
import { LocationTagData } from 'types/entity';
import { Location } from 'types/upload';
@@ -16,25 +17,38 @@ class LocationSearchService {
private cities: Array<City> = [];
private citiesPromise: Promise<void>;
- loadCities() {
- if (this.citiesPromise) {
- return;
- }
- this.citiesPromise = fetch(CITIES_URL).then((response) => {
- return response.json().then((data) => {
- this.cities = data['data'];
+ async loadCities() {
+ try {
+ if (this.citiesPromise) {
+ return;
+ }
+ this.citiesPromise = fetch(CITIES_URL).then((response) => {
+ return response.json().then((data) => {
+ this.cities = data['data'];
+ });
});
- });
+ await this.citiesPromise;
+ } catch (e) {
+ logError(e, 'LocationSearchService loadCities failed');
+ this.citiesPromise = null;
+ }
}
async searchCities(searchTerm: string) {
- if (!this.citiesPromise) {
- this.loadCities();
+ try {
+ if (!this.citiesPromise) {
+ this.loadCities();
+ }
+ await this.citiesPromise;
+ return this.cities.filter((city) => {
+ return city.city
+ .toLowerCase()
+ .startsWith(searchTerm.toLowerCase());
+ });
+ } catch (e) {
+ logError(e, 'LocationSearchService searchCities failed');
+ throw e;
}
- await this.citiesPromise;
- return this.cities.filter((city) => {
- return city.city.toLowerCase().startsWith(searchTerm.toLowerCase());
- });
}
}