Skip to content

Commit

Permalink
feat(ts/createDetourMachine): default fetchNearestIntersection resu…
Browse files Browse the repository at this point in the history
…lt to an Em Dash on error
  • Loading branch information
firestack committed Mar 11, 2025
1 parent 51ace19 commit 16477f2
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions assets/src/models/createDetourMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,23 @@ export const createDetourMachine = setup({
}),

"fetch-nearest-intersection": fromPromise<
Awaited<ReturnType<typeof fetchNearestIntersection>>,
Awaited<string>,
{
startPoint?: ShapePoint
}
>(async ({ input: { startPoint } }) => {
if (!startPoint) {
throw "Missing nearest intersection inputs"
}
return fetchNearestIntersection(startPoint.lat, startPoint.lon)

const intersection = await fetchNearestIntersection(
startPoint.lat,
startPoint.lon
)
if (intersection === null) {
throw new Error("Retrieving Intersection Failed")
}
return intersection
}),

"fetch-detour-directions": fromPromise<
Expand Down Expand Up @@ -219,6 +227,10 @@ export const createDetourMachine = setup({
finishedDetour: undefined,
detourShape: undefined,
}),
"set.nearest-intersection-fallback": assign({
// fallback to an em-dash on error
nearestIntersection: "—",
}),
},
}).createMachine({
id: "Detours Machine",
Expand Down Expand Up @@ -377,6 +389,7 @@ export const createDetourMachine = setup({
() => {
fullStoryEvent("Placed Detour Start Point", {})
},
"set.nearest-intersection-fallback",
],
},
},
Expand All @@ -395,7 +408,9 @@ export const createDetourMachine = setup({
}),
},

onError: {},
onError: {
actions: "set.nearest-intersection-fallback",
},
},
{
src: "fetch-detour-directions",
Expand Down

0 comments on commit 16477f2

Please sign in to comment.