Skip to content

Commit e626f17

Browse files
committed
Apply PR feedback from AI agents
1 parent 902d556 commit e626f17

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

apps/ensapi/src/handlers/registrar-actions-api.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import z from "zod/v4";
33

44
import {
55
buildPageContext,
6+
buildResultInternalServerError,
67
buildResultOkTimestamped,
78
buildResultServiceUnavailable,
89
type Node,
@@ -276,7 +277,11 @@ app.get(
276277
// Middleware ensures indexingStatus is available and not an Error
277278
// This check is for TypeScript type safety
278279
if (!c.var.indexingStatus || c.var.indexingStatus instanceof Error) {
279-
throw new Error("Invariant violation: indexingStatus should be validated by middleware");
280+
const result = buildResultInternalServerError(
281+
"Invariant(registrar-actions-api): indexingStatus must be available in the application context",
282+
);
283+
284+
return resultIntoHttpResponse(c, result);
280285
}
281286

282287
const { parentNode } = c.req.valid("param");

apps/ensapi/src/lib/handlers/validate.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { buildResultInvalidRequest } from "@ensnode/ensnode-sdk";
88
import { resultIntoHttpResponse } from "@/lib/result/result-into-http-response";
99

1010
/**
11-
* Creates a Hono validation middleware with custom error formatting.
11+
* Creates a Hono validation middleware.
1212
*
13-
* Wraps the Hono validator with custom error handling that uses the
14-
* errorResponse function for consistent error formatting across the API.
13+
* Wraps the Hono validator with custom error handling that uses standardized
14+
* response data model across the API.
1515
*
1616
* @param target - The validation target (param, query, json, etc.)
1717
* @param schema - The Zod schema to validate against
@@ -22,12 +22,13 @@ export const validate = <T extends ZodType, Target extends keyof ValidationTarge
2222
schema: T,
2323
) =>
2424
validator(target, schema, (result, c) => {
25-
// if validation failed, return our custom-formatted ErrorResponse instead of default
25+
// Respond with the invalid request result if validation failed.
2626
if (!result.success) {
2727
// Convert Standard Schema issues to ZodError for consistent formatting
2828
const schemaError = new SchemaError(result.error);
2929
const zodError = new ZodError(schemaError.issues as ZodError["issues"]);
30+
const errorMessage = prettifyError(zodError);
3031

31-
return resultIntoHttpResponse(c, buildResultInvalidRequest(prettifyError(zodError)));
32+
return resultIntoHttpResponse(c, buildResultInvalidRequest(errorMessage));
3233
}
3334
});

0 commit comments

Comments
 (0)