Mugetsu
Mugetsu
Explore posts from servers
TtRPC
Created by Mugetsu on 10/10/2024 in #❓-help
How to get a TRPCClientError shape as in initTRPC errorFormatter for testing
OK nvm. Just found implementation of trpclienterror and you can do
new TRPCClientError('test3', {
result: { error: { data: { apiError: [] } } },
}),
new TRPCClientError('test3', {
result: { error: { data: { apiError: [] } } },
}),
4 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 10/2/2024 in #questions
tRPC mutation onError handler error type for shared logic
Thanks ! Yeah i needed to assert the error type inside the handler and make error param of unknow type
5 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 9/3/2024 in #questions
Use Zod schema after parse & transform as a new schema
Thanks @Jacob it helped me a lot with ur suggestions!
7 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 9/9/2024 in #questions
New Zod schema based on an existing one, with some fields having different validation rules?
Well it seems to be working. Extend here seems better choice after playing with it as it need less z props through out. Thank you for suggestion ! ❤️
5 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 9/3/2024 in #questions
Use Zod schema after parse & transform as a new schema
@Jacob yes, exactly.
7 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 9/3/2024 in #questions
typescript object util library
Particularly I need to flatten keys of deeply nested objects to strings and being able to set/get/pick via string keys
9 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 9/3/2024 in #questions
typescript object util library
Doesn’t seem like accessing object via “property.x.b.c” is basic language stuff. My question might be misleading a little bit. I was referring to string dot notation keys. Sorry
9 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 8/28/2024 in #questions
Use ReactQuery to fetch different api resource than trpc resource
Yeah. Exactly what I found just after posting the question 🤦‍♂️ nonetheless thanks for answering as its what I was asking for ! Thank you ❤️
5 replies
TtRPC
Created by Mugetsu on 1/22/2024 in #❓-help
Controller is already closed crash
@JLN hi. No. I still experience these errors but simply ignore them atm. They happen from time to time
7 replies
TtRPC
Created by Mugetsu on 2/14/2024 in #❓-help
onError callback type
This seems to work but not sure if this is any better approach.

export type DownloadTriggerOnError =
| TRPCClientErrorLike<AppRouter>
| Error
| undefined;

export type DownloadTriggerOnError =
| TRPCClientErrorLike<AppRouter>
| Error
| undefined;
6 replies
TtRPC
Created by Mugetsu on 2/14/2024 in #❓-help
onError callback type
It doesnt satisfiy the constrain TS2344: Type  unknown  does not satisfy the constraint  ErrorInferrable
6 replies
TtRPC
Created by Mugetsu on 2/10/2024 in #❓-help
How to extract mutation type
I thought I had a problem with payload: RouterInputs['batch']['triggerDownload'], but after restarting TS its working. So all good now 🙂
11 replies
TtRPC
Created by Mugetsu on 2/10/2024 in #❓-help
How to extract mutation type
RouterInputs are these.
/**
* Inference helper for inputs.
* @example type HelloInput = RouterInputs['example']['hello']
*/
export type RouterInputs = inferRouterInputs<AppRouter>;

/**
* Inference helper for outputs.
* @example type HelloOutput = RouterOutputs['example']['hello']
*/
export type RouterOutputs = inferRouterOutputs<AppRouter>;

export type ReactQueryOptions = inferReactQueryProcedureOptions<AppRouter>;
/**
* Inference helper for inputs.
* @example type HelloInput = RouterInputs['example']['hello']
*/
export type RouterInputs = inferRouterInputs<AppRouter>;

/**
* Inference helper for outputs.
* @example type HelloOutput = RouterOutputs['example']['hello']
*/
export type RouterOutputs = inferRouterOutputs<AppRouter>;

export type ReactQueryOptions = inferReactQueryProcedureOptions<AppRouter>;
11 replies
TtRPC
Created by Mugetsu on 2/10/2024 in #❓-help
How to extract mutation type
Thanks guys. Altough I cant seem to get it working with InferReactQueryOptions I managed to take te routerinputs and seems working like that
export type MutateTrigger = (
payload: RouterInputs['batch']['triggerDownload'],
) => void;
export type MutateTrigger = (
payload: RouterInputs['batch']['triggerDownload'],
) => void;
11 replies
TtRPC
Created by Mugetsu on 1/22/2024 in #❓-help
Controller is already closed crash
So after some digging I found that the fetch request inside the tRPC procedure is causing this error to happen. It's not clear to me why this happens but when I have such procedure
export const appRouter = createTRPCRouter({
getSchemas: procedure.query(async ({ ctx }) => {
try {
const response = await fetch(
`${serverEnv.LOCATION_SERVICE_URL}/v4/schemas`,
{
headers: {
Authorization: `Bearer ${ctx.sessionIdToken}`,
},
},
);
const apiSchemas = await response.json();
const currentSchemaId = cookies().get(SCHEMA_COOKIE_KEY)?.value;
const locationsSchema = new LocationSchema(
apiSchemas.locationSchemas,
currentSchemaId,
);

return locationsSchema.toJSON();
} catch (e) {
trpcLogger.error(e, 'Error getting schema');

return undefined;
}
}),

post: postRouter,
});
export const appRouter = createTRPCRouter({
getSchemas: procedure.query(async ({ ctx }) => {
try {
const response = await fetch(
`${serverEnv.LOCATION_SERVICE_URL}/v4/schemas`,
{
headers: {
Authorization: `Bearer ${ctx.sessionIdToken}`,
},
},
);
const apiSchemas = await response.json();
const currentSchemaId = cookies().get(SCHEMA_COOKIE_KEY)?.value;
const locationsSchema = new LocationSchema(
apiSchemas.locationSchemas,
currentSchemaId,
);

return locationsSchema.toJSON();
} catch (e) {
trpcLogger.error(e, 'Error getting schema');

return undefined;
}
}),

post: postRouter,
});
And I do manually refresh my app (browser refresh) fast enough multiple times in a row the query errors and then it throws Invalid state: Controller is already closed and crash the app. When I just remove the fetch call it never throws that controller error but I still can see enigmatic error for the query in the console.
7 replies
TtRPC
Created by Mugetsu on 1/22/2024 in #❓-help
Controller is already closed crash
this is really bothering me and I cant find the problem with this. This error completely crashes my app
7 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 1/9/2024 in #questions
Logging trpc errors in production
P.S. Im using custom PINO logger and not deploying to vercel
4 replies
TtRPC
Created by Mugetsu on 1/9/2024 in #❓-help
LoggerLink logging only via server logger in prod
Is it fine like this??
loggerLink({
logger: (op) => {
if (op.direction === 'down' && op.result instanceof Error) {
trpcLogger.error(op.result);
trpcLogger.error(
op.result.cause?.cause,
'Aggregated trpc error cause',
);
}
},
enabled: (op) =>
process.env.NODE_ENV === 'development' ||
(op.direction === 'down' && op.result instanceof Error),
}),
loggerLink({
logger: (op) => {
if (op.direction === 'down' && op.result instanceof Error) {
trpcLogger.error(op.result);
trpcLogger.error(
op.result.cause?.cause,
'Aggregated trpc error cause',
);
}
},
enabled: (op) =>
process.env.NODE_ENV === 'development' ||
(op.direction === 'down' && op.result instanceof Error),
}),
3 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 11/30/2023 in #questions
TRPC Server error handling?
my apology. Out of habit 🤦‍♂️
6 replies
TtRPC
Created by GamerZero on 9/12/2023 in #❓-help
Cannot set headers in procedures with fetch adapter
@GamerZero did you find anything related to your issue?
6 replies