diff --git a/.changeset/yellow-bags-learn.md b/.changeset/yellow-bags-learn.md new file mode 100644 index 0000000000..585812d694 --- /dev/null +++ b/.changeset/yellow-bags-learn.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/store-indexer": minor +--- + +The `/api/logs` indexer endpoint is now returning a `404` snapshot not found error when no snapshot is found for the provided filter instead of an empty `200` response. diff --git a/packages/store-indexer/src/postgres/apiRoutes.ts b/packages/store-indexer/src/postgres/apiRoutes.ts index dfaf74990e..4f877086a5 100644 --- a/packages/store-indexer/src/postgres/apiRoutes.ts +++ b/packages/store-indexer/src/postgres/apiRoutes.ts @@ -32,8 +32,15 @@ export function apiRoutes(database: Sql): Middleware { benchmark("query records"); const logs = records.map(recordToLog); benchmark("map records to logs"); - const blockNumber = records[0]?.chainBlockNumber ?? "-1"; + if (records.length === 0) { + ctx.status = 404; + ctx.body = "no logs found"; + debug(`no logs found for chainId ${options.chainId}, address ${options.address}, filters ${options.filters}`); + return; + } + + const blockNumber = records[0].chainBlockNumber; ctx.body = JSON.stringify({ blockNumber, logs }); ctx.status = 200; } catch (error) {