Comparing two approaches for geocoding in TypeScript
Which is more idiomatic:
or:
or is there a more sensible way to do this?
export const isMapsRequestError = (
err: unknown
): err is google.maps.MapsRequestError =>
err instanceof google.maps.MapsRequestError;
export const geocode = (address: string) =>
Effect.tryPromise({
try: () => new window.google.maps.Geocoder().geocode({ address }),
catch: (err) =>
isMapsRequestError(err)
? err.code
: google.maps.GeocoderStatus.UNKNOWN_ERROR,
});export const isMapsRequestError = (
err: unknown
): err is google.maps.MapsRequestError =>
err instanceof google.maps.MapsRequestError;
export const geocode = (address: string) =>
Effect.tryPromise({
try: () => new window.google.maps.Geocoder().geocode({ address }),
catch: (err) =>
isMapsRequestError(err)
? err.code
: google.maps.GeocoderStatus.UNKNOWN_ERROR,
});or:
export const geocode = (address: string) =>
Effect.tryPromise({
try: () => new window.google.maps.Geocoder().geocode({ address }),
catch: (err) =>
isMapsRequestError(err) ? Cause.fail(err) : Cause.die(err),
});export const geocode = (address: string) =>
Effect.tryPromise({
try: () => new window.google.maps.Geocoder().geocode({ address }),
catch: (err) =>
isMapsRequestError(err) ? Cause.fail(err) : Cause.die(err),
});or is there a more sensible way to do this?
