Skip to content

Commit

Permalink
Refactor error handling in tile fetching and improve optional chainin…
Browse files Browse the repository at this point in the history
…g for UUID checks
  • Loading branch information
dqunbp committed Nov 12, 2024
1 parent 38d07cd commit f11e69d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/mosaic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ async function mosaic512px(z, x, y, filters = {}) {
const metadataByUuid = {};
await Promise.all(
rows.map(async (row) => {
if (row && row.uuid) {
if (row?.uuid) {
metadataByUuid[row.uuid] = await getGeotiffMetadata(row.uuid);
}
})
Expand Down
9 changes: 8 additions & 1 deletion src/titiler_fetcher.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ async function enqueueTileFetching(tileUrl, z, x, y) {

const request = tileRequestQueue
.add(() => fetchTile(url), { priority: z, timeout: FETCH_QUEUE_TTL })
.catch((error) => {
if (error.name === "TimeoutError") {
console.error(`Tile request timed out after ${FETCH_QUEUE_TTL}ms for URL: ${url}`);
} else {
console.error(`Error fetching tile: ${url}`, error);
}
})
.finally(() => {
activeTileRequests.delete(url);
});
Expand All @@ -64,7 +71,7 @@ async function fetchTileMetadata(uuid) {
const metadata = await got(url.href).json();
return metadata;
} catch (err) {
if (err.response && (err.response.statusCode === 404 || err.response.statusCode === 500)) {
if (err?.response?.statusCode in [404, 500]) {
return null;
} else {
throw err;
Expand Down

0 comments on commit f11e69d

Please sign in to comment.