aryzing
aryzing
TtRPC
Created by aryzing on 11/3/2023 in #❓-help
Can middleware be used on a router?
Given a router where all procedures need to use the same middleware, can the middleware be somehow attached to the router instead of manually to routes? For example, given an "admin" router, it would be quite catastrophic if one of the endpoints was accidentally set up with a publicProcedure instead of adminProcedure = publicProcedure.use(isAdmin).
4 replies
TtRPC
Created by aryzing on 11/1/2023 in #❓-help
How to limit payload size?
Is there a way to limit the payload size? E.g., if a particularly large JSON payload is sent to the (standalone) server, the server should stop after having read a set number of bytes and fail the request.
4 replies
TtRPC
Created by aryzing on 11/1/2023 in #❓-help
Feature or happy accident: error message from `cause` being used as TRPC's error message
When a procedure throws a TRPC error with no message, it turns out that if the thrown error has a cause, and the cause has a message, the cause's message will be used as the TRPC error message returned to the client. Is this on purpose or an accident? Couldn't find this behavior documented.
2 replies
TtRPC
Created by aryzing on 10/31/2023 in #❓-help
How to configure context for a standalone server?
Are there any examples out there on how to set up context for a standalone server? The docs do include an example for next , although it doesn't help much in setting one up for a standalone server. How is context set up for a standalone server?
6 replies
TtRPC
Created by aryzing on 10/31/2023 in #❓-help
Docs hard to follow with so much `next` code
Not having a great experience with the docs. There are many examples that use next, making it hard to understand what should be done in cases where next isn't being used. Take the docs on setting up the context: https://trpc.io/docs/server/context. They're entirely next focused. To what extent is Vercel's sponsorship affecting the docs?
3 replies
TtRPC
Created by aryzing on 10/31/2023 in #❓-help
How to make typed error responses in the context of a specific query?
Each query has a typed (success) response, although it seems all queries have a shared type for the error response. Is there a way of having per-query typed error responses? Is there a better alternative to having an error within a successful response, as below?
const appRouter = router({
foo: publicProcedure.query(() => {
const [error, data] = doSomething();

if (error) return {
isSuccess: false,
error,
};

return {
isSuccess: true,
data
};
})
});
const appRouter = router({
foo: publicProcedure.query(() => {
const [error, data] = doSomething();

if (error) return {
isSuccess: false,
error,
};

return {
isSuccess: true,
data
};
})
});
2 replies
TtRPC
Created by aryzing on 10/31/2023 in #❓-help
What's the negative code returned in error responses?
What's the negative error code returned in errors responses and how is it meant to be used by the client?
6 replies
TtRPC
Created by aryzing on 9/6/2023 in #❓-help
How to serve files with trpc?
Is is possible to serve files with trpc? E.g., by creating a middleware and returning directly from the middleware? I can't seem to serve files with trpc. Should a separate server be set up just for file serving?
3 replies