Skip to content

Commit 0d764a0

Browse files
author
Alex Sedighi
authored
feat(clk-gateway): prefer 4xx over 5xx when error is parsable (#76)
2 parents 6c3e343 + bf19394 commit 0d764a0

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

clk-gateway/src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ app.get(
125125
owner,
126126
});
127127
} catch (error) {
128+
if (isParsableError(error)) {
129+
const decodedError = CLICK_NAME_SERVICE_INTERFACE.parseError(
130+
error.data,
131+
);
132+
if (decodedError !== null && typeof decodedError.name === "string") {
133+
if (decodedError.name === "ERC721NonexistentToken") {
134+
res.status(404).send({ error: "Name not found" });
135+
return;
136+
}
137+
if (decodedError.name === "NameExpired") {
138+
res.status(410).send({ error: "Name expired" });
139+
return;
140+
}
141+
}
142+
}
128143
const errorMessage =
129144
error instanceof Error ? error.message : String(error);
130145
res.status(500).send({ error: errorMessage });

clk-gateway/src/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export const CLICK_NAME_SERVICE_INTERFACE = new Interface([
4444
"function expires(uint256 key) public view returns (uint256)",
4545
"function register(address to, string memory name)",
4646
"function resolve(string memory name) external view returns (address)",
47+
"error NameExpired(address oldOwner, uint256 expiredAt)",
48+
"error ERC721NonexistentToken(uint256 tokenId)",
4749
]);
4850

4951
// The storage slot of ERC721._owners within the ClickNameService contract

0 commit comments

Comments
 (0)