52 lines
1.0 KiB
TypeScript
52 lines
1.0 KiB
TypeScript
import { TRPCError } from "@trpc/server"
|
|
|
|
export function unauthorizedError(cause?: unknown) {
|
|
return new TRPCError({
|
|
code: "UNAUTHORIZED",
|
|
message: `Unauthorized`,
|
|
cause,
|
|
})
|
|
}
|
|
|
|
export function forbiddenError(cause?: unknown) {
|
|
return new TRPCError({
|
|
code: "FORBIDDEN",
|
|
message: `Forbidden`,
|
|
cause,
|
|
})
|
|
}
|
|
|
|
export function badRequestError(cause?: unknown) {
|
|
return new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message: `Bad request`,
|
|
cause,
|
|
})
|
|
}
|
|
|
|
export function notFound(cause?: unknown) {
|
|
return new TRPCError({
|
|
code: "NOT_FOUND",
|
|
message: `Not found`,
|
|
cause,
|
|
})
|
|
}
|
|
|
|
export function internalServerError(cause?: unknown) {
|
|
return new TRPCError({
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
message: `Internal Server Error`,
|
|
cause,
|
|
})
|
|
}
|
|
|
|
export const SESSION_EXPIRED = "SESSION_EXPIRED"
|
|
export class SessionExpiredError extends Error {}
|
|
export function sessionExpiredError() {
|
|
return new TRPCError({
|
|
code: "UNAUTHORIZED",
|
|
message: SESSION_EXPIRED,
|
|
cause: new SessionExpiredError(SESSION_EXPIRED),
|
|
})
|
|
}
|