From 051b6dce78b9c023ddd08b3dd700ae3df8e0b55b Mon Sep 17 00:00:00 2001 From: William Moraes Date: Mon, 20 May 2024 19:20:47 -0300 Subject: [PATCH] feat: :sparkles: throw not found error when has no user shelter --- src/server/api/routers/shelter.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/server/api/routers/shelter.ts b/src/server/api/routers/shelter.ts index 41e66e6..e8b9c49 100644 --- a/src/server/api/routers/shelter.ts +++ b/src/server/api/routers/shelter.ts @@ -1,5 +1,6 @@ -import { type z, z as zod } from "zod"; +import { z } from "zod"; import { shelterSchema } from "~/schemas/shelter"; +import { TRPCError } from "@trpc/server"; import { createTRPCRouter, @@ -14,8 +15,8 @@ export const shelterRouter = createTRPCRouter({ }), findById: publicProcedure .input( - zod.object({ - id: zod.number(), + z.object({ + id: z.number(), }), ) .query(async (opts) => { @@ -28,7 +29,10 @@ export const shelterRouter = createTRPCRouter({ }); if (!result) { - throw new Error("Shelter not found"); + throw new TRPCError({ + code: "NOT_FOUND", + message: "The server cannot find the requested resource.", + }); } return { @@ -56,8 +60,8 @@ export const shelterRouter = createTRPCRouter({ }), findUserShelterById: protectedProcedure .input( - zod.object({ - id: zod.number(), + z.object({ + id: z.number(), }), ) .query(async ({ ctx, input }) => { @@ -69,7 +73,10 @@ export const shelterRouter = createTRPCRouter({ }); if (!result) { - throw new Error("Shelter not found"); + throw new TRPCError({ + code: "NOT_FOUND", + message: "The server cannot find the requested resource.", + }); } return { @@ -159,8 +166,8 @@ export const shelterRouter = createTRPCRouter({ }), delete: protectedProcedure .input( - zod.object({ - id: zod.number(), + z.object({ + id: z.number(), }), ) .mutation(async ({ ctx, input }) => {