Skip to content

Commit

Permalink
fix metadata loading error reporting
Browse files Browse the repository at this point in the history
Signed-off-by: Ihor Dykhta <[email protected]>
  • Loading branch information
igorDykhta committed Jan 9, 2025
1 parent 0926e24 commit c374c26
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/components/src/hooks/use-fetch-vector-tile-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export default function useFetchVectorTileMetadata({
: PMTilesSource.createDataSource(url, {});

const metadata = await tileSource.metadata;
// Since we switched to PMTilesSource.createDataSource response errors aren't available here
if (!metadata) {
throw new Error('Failed to fetch metadata');
}
setProcessedData(metadata);
} catch (metadataError) {
setError(metadataError as any);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const LoadDataFooterContainer = styled.div.attrs({

const ErrorContainer = styled.div`
color: red;
padding-right: 15px;
padding-left: 15px;
display: inline-block;
`;

type LoadDataFooterProps = {
Expand All @@ -47,7 +48,7 @@ type LoadDataFooterProps = {
onConfirm: () => void;
confirmText: string;
prependText?: string;
errorText?: string;
errorText?: string | null;
};

const LoadDataFooter: React.FC<LoadDataFooterProps & WrappedComponentProps> = ({
Expand All @@ -62,7 +63,6 @@ const LoadDataFooter: React.FC<LoadDataFooterProps & WrappedComponentProps> = ({
return (
<LoadDataFooterContainer>
<div>
{errorText && <ErrorContainer>{errorText}</ErrorContainer>}
{prependText}
<AddDataButton
disabled={disabled}
Expand All @@ -78,6 +78,7 @@ const LoadDataFooter: React.FC<LoadDataFooterProps & WrappedComponentProps> = ({
id: confirmText
})}
</AddDataButton>
{errorText && <ErrorContainer>{errorText}</ErrorContainer>}
</div>
</LoadDataFooterContainer>
);
Expand Down
3 changes: 3 additions & 0 deletions src/components/src/modals/tilesets-modals/load-tileset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ function LoadTilesetTabFactory() {
*/}
<div>
<CurrentForm setResponse={setResponse} />
{/**
{error && <div>{getError(error)}</div>}
*/}
</div>
</div>
<MetaContainer>
Expand All @@ -162,6 +164,7 @@ function LoadTilesetTabFactory() {
isLoading={loading || isAddingDatasets}
onConfirm={createTileDataset}
confirmText="tilesetSetup.addTilesetText"
errorText={error && getError(error)}
/>
</LoadTilesetTabContainer>
);
Expand Down
28 changes: 24 additions & 4 deletions src/components/src/modals/tilesets-modals/tileset-vector-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const TilesetVectorForm: React.FC<TilesetVectorFormProps> = ({setResponse}) => {
const [tileName, setTileName] = useState<string>('');
const [tileUrl, setTileUrl] = useState<string>('');
const [metadataUrl, setMetadataUrl] = useState<string | null>('');
const [initialFetchError, setInitialFetchError] = useState<Error | null>(null);

const onTileNameChange = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -89,14 +90,24 @@ const TilesetVectorForm: React.FC<TilesetVectorFormProps> = ({setResponse}) => {
if (!metadataUrl && potentialMetadataUrl) {
// check if URL exists before setting it as the metadata URL
const resp = await fetch(potentialMetadataUrl);
if (resp.ok) setMetadataUrl(potentialMetadataUrl);
if (resp.ok) {
setInitialFetchError(null);
setMetadataUrl(potentialMetadataUrl);
} else {
setInitialFetchError(
new Error(`Metadata loading failed: ${resp.status} ${resp.statusText}`)
);
}
} else {
setInitialFetchError(null);
}
if (!tileName) {
setTileName(newTileUrl.split('/').pop() || newTileUrl);
}
},
[setTileUrl, tileName, setMetadataUrl, metadataUrl]
);

const process = useMemo(() => {
return (value: PMTilesMetadata | TileJSON) =>
parseVectorMetadata(value, {tileUrl: metadataUrl});
Expand All @@ -123,17 +134,26 @@ const TilesetVectorForm: React.FC<TilesetVectorFormProps> = ({setResponse}) => {
metadata,
dataset,
loading,
error: metaError
error: metaError || initialFetchError
});
} else {
setResponse({
metadata,
dataset: null,
loading,
error: metaError
error: metaError || initialFetchError
});
}
}, [setResponse, metadata, loading, metaError, tileUrl, tileName, metadataUrl]);
}, [
setResponse,
metadata,
loading,
metaError,
initialFetchError,
tileUrl,
tileName,
metadataUrl
]);

useEffect(() => {
if (metadata) {
Expand Down

0 comments on commit c374c26

Please sign in to comment.