Skip to content

Commit

Permalink
feat: ✨ throw not found error when has no user shelter
Browse files Browse the repository at this point in the history
  • Loading branch information
willMoraes committed May 20, 2024
1 parent 123e82a commit 051b6dc
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/server/api/routers/shelter.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -14,8 +15,8 @@ export const shelterRouter = createTRPCRouter({
}),
findById: publicProcedure
.input(
zod.object({
id: zod.number(),
z.object({
id: z.number(),
}),
)
.query(async (opts) => {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 }) => {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 }) => {
Expand Down

0 comments on commit 051b6dc

Please sign in to comment.