Skip to content

Commit

Permalink
Merge pull request hotosm#265 from natrimmer/219-show-proper-message-…
Browse files Browse the repository at this point in the history
…when-raw-data-API-is-down

Closes hotosm#219 [Show proper message when Raw data API is down]
  • Loading branch information
kshitijrajsharma authored Aug 8, 2024
2 parents 32dd72b + 74939c6 commit feacf8e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions frontend/src/components/Layout/TrainingDS/DatasetEditor/AOI.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const AOI = (props) => {
const [openSnack, setOpenSnack] = useState(false);
const [fileError, setFileError] = useState(null);
const [geoJsonFile, setGeoJsonFile] = useState(null);
const [fetchError, setFetchError] = useState(null);

let _DATA = usePagination(
props.mapLayers.filter((e) => e.type === "aoi"),
PER_PAGE
Expand All @@ -80,6 +82,7 @@ const AOI = (props) => {

const { accessToken } = useContext(AuthContext);
const fetchOSMLebels = async (aoiId) => {
setFetchError(null);
try {
const headers = {
"access-token": accessToken,
Expand All @@ -91,15 +94,21 @@ const AOI = (props) => {

if (res.error) {
console.log(res.error.response.statusText);
setFetchError("Failed to fetch OSM data. Please try again.");
} else {
return res.data;
}
} catch (e) {
console.log("isError", e);
setFetchError("Failed to fetch OSM data. Please check your connection.");
}
};
const { mutate: mutateFetch, data: fetchResult } =
useMutation(fetchOSMLebels);

const { mutate: mutateFetch } = useMutation(fetchOSMLebels, {
onError: () => {
setFetchError("Failed to fetch OSM data. Please try again.");
},
});

const DeleteAOI = async (id, leafletId) => {
try {
Expand Down Expand Up @@ -408,6 +417,11 @@ const AOI = (props) => {
))}
</List>
</Demo>
{fetchError && (
<Typography variant="body2">
{fetchError}
</Typography>
)}
{props.mapLayers && props.mapLayers.length === 0 && (
<Typography variant="body1" component="h2">
No TAs yet, start creating one by clicking Draw a rectangle, 3rd
Expand Down

0 comments on commit feacf8e

Please sign in to comment.