-
Notifications
You must be signed in to change notification settings - Fork 15
Improve how the ENSRainbow client handles network errors #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a515ab8
29789e6
095bf04
5701621
a59d40a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| import packageJson from "@/../package.json"; | ||
| import type { EnsRainbow } from "@ensnode/ensrainbow-sdk"; | ||
| import { StatusCode } from "@ensnode/ensrainbow-sdk"; | ||
| import { Hono } from "hono"; | ||
| import type { Context as HonoContext } from "hono"; | ||
| import { cors } from "hono/cors"; | ||
|
|
||
| import packageJson from "@/../package.json"; | ||
| import { ENSRainbowDB, SCHEMA_VERSION } from "@/lib/database"; | ||
| import { ENSRainbowServer } from "@/lib/server"; | ||
| import { logger } from "@/utils/logger"; | ||
| import type { ContentfulStatusCode } from "hono/utils/http-status"; | ||
| import { logger } from "../utils/logger"; | ||
| import { ENSRainbowDB, SCHEMA_VERSION } from "./database"; | ||
| import { ENSRainbowServer } from "./server"; | ||
|
|
||
| /** | ||
| * Creates and configures an ENS Rainbow api | ||
|
|
@@ -32,7 +32,11 @@ export async function createApi(db: ENSRainbowDB): Promise<Hono> { | |
| logger.debug(`Healing request for labelhash: ${labelhash}`); | ||
| const result = await server.heal(labelhash); | ||
| logger.debug(`Heal result:`, result); | ||
| return c.json(result, result.errorCode); | ||
|
|
||
| // Map error codes > 1000 to 500, otherwise use the original code | ||
| const statusCode = result.errorCode && result.errorCode >= 1000 ? 500 : result.errorCode; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are new error codes defined: |
||
|
|
||
| return c.json(result, statusCode as ContentfulStatusCode); | ||
| }); | ||
|
|
||
| api.get("/health", (c: HonoContext) => { | ||
|
|
@@ -45,7 +49,11 @@ export async function createApi(db: ENSRainbowDB): Promise<Hono> { | |
| logger.debug("Label count request"); | ||
| const result = await server.labelCount(); | ||
| logger.debug(`Count result:`, result); | ||
| return c.json(result, result.errorCode); | ||
|
|
||
| // Map error codes > 1000 to 500, otherwise use the original code | ||
| const statusCode = result.errorCode && result.errorCode >= 1000 ? 500 : result.errorCode; | ||
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return c.json(result, statusCode as ContentfulStatusCode); | ||
| }); | ||
|
|
||
| api.get("/v1/version", (c: HonoContext) => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok?