🔊 Add response debug log for failing requests without errors

This commit is contained in:
Baptiste Arnaud
2023-11-17 15:42:40 +01:00
parent 3a47a0fcbd
commit 5298538ecb
7 changed files with 17 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.2.21",
"version": "0.2.22",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",

View File

@@ -51,7 +51,7 @@ export const Bot = (props: BotProps & { class?: string }) => {
typeof props.typebot === 'string' ? props.typebot : undefined
const isPreview =
typeof props.typebot !== 'string' || (props.isPreview ?? false)
const { data, error } = await startChatQuery({
const { data, error, response } = await startChatQuery({
stripeRedirectStatus: urlParams.get('redirect_status') ?? undefined,
typebot: props.typebot,
apiHost: props.apiHost,
@@ -81,6 +81,7 @@ export const Bot = (props: BotProps & { class?: string }) => {
if (!data) {
if (error) console.error(error)
console.error({ data, error, response })
return setError(new Error("Error! Couldn't initiate the chat."))
}

View File

@@ -41,7 +41,7 @@ export async function startChatQuery({
: undefined
if (paymentInProgressState) {
removePaymentInProgressFromStorage()
const { data, error } = await sendRequest<InitialChatReply>({
const { data, error, response } = await sendRequest<InitialChatReply>({
method: 'POST',
url: `${isNotEmpty(apiHost) ? apiHost : guessApiHost()}/api/v1/sessions/${
paymentInProgressState.sessionId
@@ -64,11 +64,12 @@ export async function startChatQuery({
}
: undefined,
error,
response,
}
}
const typebotId = typeof typebot === 'string' ? typebot : typebot.id
if (isPreview) {
const { data, error } = await sendRequest<InitialChatReply>({
const { data, error, response } = await sendRequest<InitialChatReply>({
method: 'POST',
url: `${
isNotEmpty(apiHost) ? apiHost : guessApiHost()
@@ -82,10 +83,11 @@ export async function startChatQuery({
return {
data,
error,
response,
}
}
const { data, error } = await sendRequest<InitialChatReply>({
const { data, error, response } = await sendRequest<InitialChatReply>({
method: 'POST',
url: `${
isNotEmpty(apiHost) ? apiHost : guessApiHost()
@@ -100,5 +102,6 @@ export async function startChatQuery({
return {
data,
error,
response,
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@typebot.io/nextjs",
"version": "0.2.21",
"version": "0.2.22",
"description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View File

@@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.2.21",
"version": "0.2.22",
"description": "Convenient library to display typebots on your React app",
"main": "dist/index.js",
"types": "dist/index.d.ts",