update to raise NOT_FOUND error when no resource found
This commit is contained in:
parent
f180fb8fd1
commit
8895fc31b4
@ -18,6 +18,8 @@ export function QueryWaitWrapper<TData, TError>({
|
||||
return <LoadingBarChart width={200} height={200} />;
|
||||
}
|
||||
|
||||
console.log(query.data);
|
||||
|
||||
if (!query.data || query.isError) {
|
||||
return (
|
||||
<div className="my-10 sm:my-16 md:my-28">
|
||||
|
@ -12,7 +12,7 @@ import { api } from "~/utils/api";
|
||||
import { useRouter } from "next/router";
|
||||
import { HeaderFooterLayout } from "~/layouts/HeaderFooterLayout";
|
||||
import { QueryWaitWrapper } from "~/components/LoadingWrapper";
|
||||
import { AuditoryResource } from "@prisma/client";
|
||||
import { type AuditoryResource } from "@prisma/client";
|
||||
|
||||
const EditResourcePage = () => {
|
||||
const router = useRouter();
|
||||
@ -20,7 +20,13 @@ const EditResourcePage = () => {
|
||||
|
||||
const resourceQuery = api.auditoryResource.byId.useQuery(
|
||||
{ id },
|
||||
{ enabled: router.isReady }
|
||||
{
|
||||
enabled: router.isReady,
|
||||
onError(err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const ConditionalView = (data: AuditoryResource) => {
|
||||
|
@ -1,10 +1,5 @@
|
||||
import {
|
||||
SkillLevel,
|
||||
Skill,
|
||||
Platform,
|
||||
type AuditoryResource,
|
||||
PaymentType,
|
||||
} from "@prisma/client";
|
||||
import { SkillLevel, Skill, Platform, PaymentType } from "@prisma/client";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
@ -25,13 +20,28 @@ export const auditoryResourceRouter = createTRPCRouter({
|
||||
byId: publicProcedure
|
||||
.input(z.object({ id: z.string() }))
|
||||
.query(async ({ input, ctx }) => {
|
||||
const resource = await ctx.prisma.auditoryResource.findUnique({
|
||||
where: {
|
||||
id: input.id,
|
||||
},
|
||||
});
|
||||
try {
|
||||
const resource = await ctx.prisma.auditoryResource.findUnique({
|
||||
where: {
|
||||
id: input.id,
|
||||
},
|
||||
});
|
||||
|
||||
return { ...resource } as AuditoryResource;
|
||||
if (!resource) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "The resource you are looking for was not found.",
|
||||
});
|
||||
}
|
||||
|
||||
return resource;
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "The resource you are looking for was not found.",
|
||||
cause: e,
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
||||
getAll: publicProcedure.query(({ ctx }) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user