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} />;
|
return <LoadingBarChart width={200} height={200} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(query.data);
|
||||||
|
|
||||||
if (!query.data || query.isError) {
|
if (!query.data || query.isError) {
|
||||||
return (
|
return (
|
||||||
<div className="my-10 sm:my-16 md:my-28">
|
<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 { useRouter } from "next/router";
|
||||||
import { HeaderFooterLayout } from "~/layouts/HeaderFooterLayout";
|
import { HeaderFooterLayout } from "~/layouts/HeaderFooterLayout";
|
||||||
import { QueryWaitWrapper } from "~/components/LoadingWrapper";
|
import { QueryWaitWrapper } from "~/components/LoadingWrapper";
|
||||||
import { AuditoryResource } from "@prisma/client";
|
import { type AuditoryResource } from "@prisma/client";
|
||||||
|
|
||||||
const EditResourcePage = () => {
|
const EditResourcePage = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@ -20,7 +20,13 @@ const EditResourcePage = () => {
|
|||||||
|
|
||||||
const resourceQuery = api.auditoryResource.byId.useQuery(
|
const resourceQuery = api.auditoryResource.byId.useQuery(
|
||||||
{ id },
|
{ id },
|
||||||
{ enabled: router.isReady }
|
{
|
||||||
|
enabled: router.isReady,
|
||||||
|
onError(err) {
|
||||||
|
console.log(err);
|
||||||
|
throw err;
|
||||||
|
},
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const ConditionalView = (data: AuditoryResource) => {
|
const ConditionalView = (data: AuditoryResource) => {
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
import {
|
import { SkillLevel, Skill, Platform, PaymentType } from "@prisma/client";
|
||||||
SkillLevel,
|
import { TRPCError } from "@trpc/server";
|
||||||
Skill,
|
|
||||||
Platform,
|
|
||||||
type AuditoryResource,
|
|
||||||
PaymentType,
|
|
||||||
} from "@prisma/client";
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -25,13 +20,28 @@ export const auditoryResourceRouter = createTRPCRouter({
|
|||||||
byId: publicProcedure
|
byId: publicProcedure
|
||||||
.input(z.object({ id: z.string() }))
|
.input(z.object({ id: z.string() }))
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const resource = await ctx.prisma.auditoryResource.findUnique({
|
try {
|
||||||
where: {
|
const resource = await ctx.prisma.auditoryResource.findUnique({
|
||||||
id: input.id,
|
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 }) => {
|
getAll: publicProcedure.query(({ ctx }) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user