rd
rd
Explore posts from servers
NNuxt
Created by rd on 7/5/2024 in #❓・help
Passing data from module hook to plugin
I have a module and need to resolve some data in the build:manifest hook, namely some resource information (name and file). I then need to access this data in a server plugin in the app:rendered hook, so I can alter some ssrContext head entries. Normally I would pass this data via the runtimeConfig, but I can't in this instance because addPlugin is called before the first hook has executed, and any config that plugin has access to will have already been resolved. Does anyone know how I can approach/resolve this? Thanks!
1 replies
NNuxt
Created by rd on 7/31/2023 in #❓・help
Client side error handling
I'm having trouble handling errors on the client side of an SSR app. They seem to handle fine on the server. In my setup of my "product" page I have the following:
if (!product) {
throw createError({ statusCode: 404, statusMessage: 'Product not found' });
}
if (!product) {
throw createError({ statusCode: 404, statusMessage: 'Product not found' });
}
So if I navigate to the URL /shop/some-product-that-doesnt-exist as the initial server rendered route and product above is false, the server handles the error and Nuxt correctly shows my ~/error.vue component. However if I click on a <NuxtLink> to the same location on the client side, nothing happens, error.vue is not rendered, and the console shows:
Uncaught (in promise) Error: Product not found
Uncaught (in promise) Error: Product not found
I've read the error handling docs several times but can't work out what I'm doing wrong, any ideas? Thanks!
2 replies
CDCloudflare Developers
Created by rd on 7/20/2023 in #workers-help
request.json() timing out
I just started with cloudflare workers, initialised a new worker using npm create cloudflare@latest and am finding the execution times out if I use request.json(). Is there anything obvious I'm missing? Even if my code is just as below, I don't get a response, but removing the logged line, I do:
export default {
async fetch(req: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
console.log(await req.json());
return new Response('Hello World!');
},
};
export default {
async fetch(req: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
console.log(await req.json());
return new Response('Hello World!');
},
};
2 replies
TtRPC
Created by rd on 6/9/2023 in #❓-help
All values in DecoratedProcedureRecord are of type any
I've stumbled across an issue and I'm not sure how to start diagnosing it... Basically in my IDE the return type of my createTRPCProxyClient<AppRouter>(...) call is a DecoratedProcedureRecord where every value is of type any. I'm seeing a lot of issues with TS seemingly struggling to work with this repo, I suspect that the types have become too complex with tRPC and the ORM I'm using. Is it possible that TS has just "given up" so returns any instead of the expected type? Or is it likely something else?
12 replies
TtRPC
Created by rd on 4/24/2023 in #❓-help
Error Handling vs Error Formatting
I'm a bit confused from the docs about how I should be handling errors on the server. The Error Handling section refers to handling errors client side right? More specifically, the ORM I'm using suggests delegating error handling to the server implementation. Where the ORM is throwing an instance of its internal NotFoundError class, I need to update the response http code to 404 and also hide the data associated with that error in production. Should I be doing this within the errorFormatter? Thanks!
8 replies
TtRPC
Created by rd on 4/6/2023 in #❓-help
Throwing fastify errors when using fastify adapter
Hello, I'm using fastifyTRPCPlugin from @trpc/server/adapters/fastify and trying to throw errors correctly. I usually use @fastify-sensible because I find the API clear, e.g. I can write things like fastify.httpErrors.forbidden() or fastify.httpErrors.unauthorized. However if I throw one of these in a tRPC procedure it seems the error code is always 500, assuming that's because tRPC is intercepting/handling them in some way? What's the best way to "solve" this? Thanks!
4 replies
TtRPC
Created by rd on 2/23/2023 in #❓-help
JSON inferred router output not matching
Hello. I have a procedure query which is returning Json from a postgresql db using Prisma. The type in the query on the server is showing up as JsonValue (definitions below). The inferred type from the router.procedure.query() on a createTRPCProxyClient instance comes back as expected, but the type definition using inferRouterOutputs<AppRouter> types the Json data as string | null. Any ideas? Thanks. New to tRPC so sorry if this is a no-brainer.
type JsonObject = { [Key in string]?: JsonValue };
interface JsonArray extends Array<JsonValue> {}
type JsonValue = string | number | boolean | JsonObject | JsonArray | null;
type JsonObject = { [Key in string]?: JsonValue };
interface JsonArray extends Array<JsonValue> {}
type JsonValue = string | number | boolean | JsonObject | JsonArray | null;
11 replies