mirror of
https://github.com/baptisteArno/typebot.io.git
synced 2026-06-05 21:04:43 +08:00
🚑️ Fix bot handler api error definition
This commit is contained in:
parent
62d3ba83f0
commit
3a0ff4b59e
@ -1,4 +1,4 @@
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { ORPCError } from "@orpc/server";
|
||||
import { BubbleBlockType } from "@typebot.io/blocks-bubbles/constants";
|
||||
import { messageSchema } from "@typebot.io/chat-api/schemas";
|
||||
import { getSession } from "@typebot.io/chat-session/queries/getSession";
|
||||
@ -40,8 +40,7 @@ export const handleContinueChat = async ({
|
||||
const session = await getSession(sessionId);
|
||||
|
||||
if (!session?.state) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
throw new ORPCError("NOT_FOUND", {
|
||||
message: "Session not found.",
|
||||
});
|
||||
}
|
||||
@ -57,8 +56,7 @@ export const handleContinueChat = async ({
|
||||
session.updatedAt.getTime() + session.state.expiryTimeout < Date.now();
|
||||
|
||||
if (isSessionExpired)
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
throw new ORPCError("NOT_FOUND", {
|
||||
message: "Session expired. You need to start a new session.",
|
||||
});
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { ORPCError } from "@orpc/server";
|
||||
import { getSession } from "@typebot.io/chat-session/queries/getSession";
|
||||
import { logInSessionSchema } from "@typebot.io/logs/schemas";
|
||||
import { z } from "@typebot.io/zod";
|
||||
@ -26,8 +26,7 @@ export const handleSaveClientLogs = async ({
|
||||
const session = await getSession(sessionId);
|
||||
|
||||
if (!session?.state) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
throw new ORPCError("NOT_FOUND", {
|
||||
message: "Session not found.",
|
||||
});
|
||||
}
|
||||
@ -40,8 +39,7 @@ export const handleSaveClientLogs = async ({
|
||||
const resultId = session.state.typebotsQueue[0].resultId;
|
||||
|
||||
if (!resultId) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
throw new ORPCError("NOT_FOUND", {
|
||||
message: "Result not found.",
|
||||
});
|
||||
}
|
||||
@ -59,8 +57,7 @@ export const handleSaveClientLogs = async ({
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("Failed to save logs", e);
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
||||
message: "Failed to save logs.",
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { ORPCError } from "@orpc/server";
|
||||
import { getSession } from "@typebot.io/chat-session/queries/getSession";
|
||||
import type { SessionState } from "@typebot.io/chat-session/schemas";
|
||||
import prisma from "@typebot.io/prisma";
|
||||
@ -24,7 +24,7 @@ export const handleUpdateTypebotInSession = async ({
|
||||
}) => {
|
||||
const session = await getSession(sessionId);
|
||||
if (!session?.state)
|
||||
throw new TRPCError({ code: "NOT_FOUND", message: "Session not found" });
|
||||
throw new ORPCError("NOT_FOUND", { message: "Session not found" });
|
||||
|
||||
const publicTypebot = (await prisma.publicTypebot.findFirst({
|
||||
where: {
|
||||
@ -54,7 +54,7 @@ export const handleUpdateTypebotInSession = async ({
|
||||
})) as Pick<PublicTypebot, "edges" | "variables" | "groups"> | null;
|
||||
|
||||
if (!publicTypebot)
|
||||
throw new TRPCError({ code: "UNAUTHORIZED", message: "Unauthorized" });
|
||||
throw new ORPCError("UNAUTHORIZED", { message: "Unauthorized" });
|
||||
|
||||
const newSessionState = updateSessionState(session.state, publicTypebot);
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { ORPCError } from "@orpc/server";
|
||||
import { getSession } from "@typebot.io/chat-session/queries/getSession";
|
||||
import { safeStringify } from "@typebot.io/lib/safeStringify";
|
||||
import { logInSessionSchema } from "@typebot.io/logs/schemas";
|
||||
@ -31,8 +31,7 @@ export const handleSaveClientLogsV1 = async ({
|
||||
const session = await getSession(sessionId);
|
||||
|
||||
if (!session?.state) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
throw new ORPCError("NOT_FOUND", {
|
||||
message: "Session not found.",
|
||||
});
|
||||
}
|
||||
@ -45,8 +44,7 @@ export const handleSaveClientLogsV1 = async ({
|
||||
const resultId = session.state.typebotsQueue[0].resultId;
|
||||
|
||||
if (!resultId) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
throw new ORPCError("NOT_FOUND", {
|
||||
message: "Result not found.",
|
||||
});
|
||||
}
|
||||
@ -71,8 +69,7 @@ export const handleSaveClientLogsV1 = async ({
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("Failed to save logs", e);
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
||||
message: "Failed to save logs.",
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user