Skip to content

Commit

Permalink
More dynamic error handling to handle server down cases differently t…
Browse files Browse the repository at this point in the history
…han path-not-found cases
  • Loading branch information
sdl60660 committed Jan 4, 2022
1 parent 37c289a commit 381e188
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
31 changes: 25 additions & 6 deletions src/components/Map.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
let aborted = false;
let vizState = "uninitialized";
let errorStatus = null;
let postRun = false;
let runTimeout;
Expand Down Expand Up @@ -237,7 +238,13 @@
currentLocation = e.lngLat;
startCoordinates = e.lngLat;
mapBounds = map.getBounds();
try {
mapBounds = map.getBounds();
} catch (e) {
// console.error(e);
return;
}
if (!mapBounds.contains(e.lngLat)) {
map.flyTo({
Expand All @@ -258,10 +265,12 @@
const initializeData = async ({ map, e }) => {
const flowlinesData = await getFlowlineData(e);
if (!flowlinesData) {
if (!flowlinesData || flowlinesData.error === true) {
errorStatus = flowlinesData;
vizState = "error";
sendQueryData(e.lngLat.lat, e.lngLat.lat, false, true);
sendQueryData(e.lngLat.lat, e.lngLat.lat, false, true);
resetMapState({ map, error: true });
return;
}
Expand Down Expand Up @@ -527,7 +536,16 @@
},
});
const responseData = (await flowlinesResponse.json()).value;
if (flowlinesResponse.status !== 200) {
return { error: true, status: "API error" };
}
const results = (await flowlinesResponse.json());
if (results.code === "fail") {
return { error: true, status: "Routing error" };
}
const responseData = results.value;
resultFound = responseData.features.length > 0;
if (resultFound) {
Expand Down Expand Up @@ -1030,6 +1048,7 @@
if (error) {
setTimeout(() => {
vizState = "uninitialized";
errorStatus = null;
}, 2000);
} else {
vizState = "uninitialized";
Expand Down Expand Up @@ -1149,7 +1168,7 @@
{/if}
</div>

<Prompt {vizState} {currentLocation} />
<Prompt {vizState} {errorStatus} {currentLocation} />
<ContactBox {vizState} />

<div
Expand Down
8 changes: 7 additions & 1 deletion src/components/Prompt.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export let currentLocation;
export let vizState;
export let errorStatus;
export let bannerVisible;
let loading = false;
Expand All @@ -26,8 +27,13 @@
} else if (vizState === "uninitialized") {
resetPrompt();
} else if (vizState === "error") {
message =
if (errorStatus?.status === "API error") {
message = "Routing Server is down! Sorry, this is likely due to high volume, try again in a bit."
}
else {
message =
"Unable to find a flowpath for that location. Please try somewhere else.";
}
loading = false;
}
Expand Down

1 comment on commit 381e188

@vercel
Copy link

@vercel vercel bot commented on 381e188 Jan 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.