complete project using prettier!
This commit is contained in:
@@ -11,7 +11,10 @@ export class GoogleGeocodingService {
|
||||
* @param logger A logger instance.
|
||||
* @returns A promise that resolves to the coordinates or null if not found.
|
||||
*/
|
||||
async geocode(address: string, logger: Logger = defaultLogger): Promise<{ lat: number; lng: number } | null> {
|
||||
async geocode(
|
||||
address: string,
|
||||
logger: Logger = defaultLogger,
|
||||
): Promise<{ lat: number; lng: number } | null> {
|
||||
const apiKey = process.env.GOOGLE_MAPS_API_KEY;
|
||||
if (!apiKey) {
|
||||
logger.error('[GoogleGeocodingService] API key is missing.');
|
||||
@@ -28,17 +31,26 @@ export class GoogleGeocodingService {
|
||||
|
||||
const data = await response.json();
|
||||
if (data.status === 'OK' && data.results.length > 0) {
|
||||
logger.info({ address, result: data.results[0].geometry.location }, `[GoogleGeocodingService] Successfully geocoded address`);
|
||||
logger.info(
|
||||
{ address, result: data.results[0].geometry.location },
|
||||
`[GoogleGeocodingService] Successfully geocoded address`,
|
||||
);
|
||||
return data.results[0].geometry.location;
|
||||
}
|
||||
|
||||
logger.warn({ address, status: data.status }, '[GoogleGeocodingService] Geocoding failed or returned no results.');
|
||||
logger.warn(
|
||||
{ address, status: data.status },
|
||||
'[GoogleGeocodingService] Geocoding failed or returned no results.',
|
||||
);
|
||||
return null;
|
||||
} catch (error) {
|
||||
logger.error({ err: error, address }, '[GoogleGeocodingService] An error occurred while calling the Google Maps API.');
|
||||
logger.error(
|
||||
{ err: error, address },
|
||||
'[GoogleGeocodingService] An error occurred while calling the Google Maps API.',
|
||||
);
|
||||
throw error; // Re-throw to allow the calling service to handle the failure (e.g., by falling back).
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const googleGeocodingService = new GoogleGeocodingService();
|
||||
export const googleGeocodingService = new GoogleGeocodingService();
|
||||
|
||||
Reference in New Issue
Block a user