File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { TRPCError } from "@trpc/server" ;
12import { router , protectedProcedure , type ProtectedContext } from "../trpc.js" ;
2- import { sessionService } from "../services/session.service.js" ;
3+ import {
4+ sessionService ,
5+ AuthorizationError ,
6+ } from "../services/session.service.js" ;
37
48export const sessionsRouter = router ( {
59 getAll : protectedProcedure . query ( async ( { ctx } ) => {
610 const userId = ( ctx as ProtectedContext ) . user . id ;
7- return await sessionService . getSessions ( ctx . db . prisma , userId ) ;
11+
12+ try {
13+ return await sessionService . getSessions ( ctx . db . prisma , userId ) ;
14+ } catch ( error ) {
15+ if ( error instanceof AuthorizationError ) {
16+ throw new TRPCError ( {
17+ code : "FORBIDDEN" ,
18+ message : error . message ,
19+ } ) ;
20+ }
21+ throw error ;
22+ }
823 } ) ,
924} ) ;
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ export type SessionWithTopics = Prisma.WeeklySessionGetPayload<{
2121 } ;
2222} > ;
2323
24- class AuthorizationError extends Error {
24+ export class AuthorizationError extends Error {
2525 constructor ( message : string ) {
2626 super ( message ) ;
2727 this . name = "AuthorizationError" ;
You can’t perform that action at this time.
0 commit comments