Skip to content

Commit

Permalink
feat(store-indexer): return a "not found" error when no snapshot is f…
Browse files Browse the repository at this point in the history
…ound for a `/api/logs` request (#2043)
  • Loading branch information
alvrs authored Dec 8, 2023
1 parent 85b9461 commit f61b4bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/yellow-bags-learn.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 8 additions & 1 deletion packages/store-indexer/src/postgres/apiRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f61b4bc

Please sign in to comment.