RPC ClientResponse not picking up response type from zValidator hook #2572
Unanswered
kosiumeigbo
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi All,
I am building a project using Hono and NextJS. The version of Hono I am currently using is 4.2.4.
I am using the RPC feature in Hono. I have grouped routes in a file. I am doing validation using the zValidator middleware. The image below is one of the routes/endpoints I have created:
I have also created a type called 'JSONResponse' to use for all my response objects. If the operation is successful, it returns an object with success true and the data. If the operation is not successful, it returns an object with success false and error property that will be the error message. It helps to keep my response standardised. This is used in the endpoint callback function above. The image below is the type definition for 'JSONResponse':
I have now imported the hc client to my NextJS server component to use the RPC route. However, I have found that the returned response from my validator hook isn't registered in the Client Response object. It only registers the returned response in the endpoint callback function, which has success as true. It does not register the response in the validation hook. This image is shown below:
It should also register the response sent from the zValidator hook so that it would look like something like this:
Therefore showing a union type between the 'success: true' object and the 'success: false' object. However, this isn't what is done. Am I doing something wrong? Thanks for the help!
Beta Was this translation helpful? Give feedback.
All reactions