Skip to content

Commit

Permalink
🔊 Add response debug log for failing requests without errors
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Nov 17, 2023
1 parent 3a47a0f commit 5298538
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"i18n-ally.enabledFrameworks": ["custom"],
"i18n-ally.sortKeys": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/js/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/embeds/js/src/components/Bot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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."))
}

Expand Down
9 changes: 6 additions & 3 deletions packages/embeds/js/src/queries/startChatQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -100,5 +102,6 @@ export async function startChatQuery({
return {
data,
error,
response,
}
}
2 changes: 1 addition & 1 deletion packages/embeds/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/react/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 5 additions & 4 deletions packages/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ export const sendRequest = async <ResponseData>(
body?: Record<string, unknown> | FormData
}
| string
): Promise<{ data?: ResponseData; error?: Error }> => {
): Promise<{ data?: ResponseData; error?: Error; response?: Response }> => {
let response
try {
const url = typeof params === 'string' ? params : params.url
const response = await fetch(url, {
response = await fetch(url, {
method: typeof params === 'string' ? 'GET' : params.method,
mode: 'cors',
headers:
Expand All @@ -47,10 +48,10 @@ export const sendRequest = async <ResponseData>(
})
const data = await response.json()
if (!response.ok) throw 'error' in data ? data.error : data
return { data }
return { data, response }
} catch (e) {
console.error(e)
return { error: e as Error }
return { error: e as Error, response }
}
}

Expand Down

3 comments on commit 5298538

@vercel
Copy link

@vercel vercel bot commented on 5298538 Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

app.blogely.com
apr.nigerias.io
aso.nigerias.io
baohanh.qmap.vn
blackcan.cr8.ai
blackvip.online
bot.4display.nl
bot.a6t-you.com
bot.artiweb.app
bot.devitus.com
bot.neobank.fun
bot.reeplai.com
bot.scayver.com
bot.tc-mail.com
carspecs.lam.ee
chat.borang.net
chat.lalmon.com
chat.sureb4.com
conversawpp.com
eventhub.com.au
feiraododia.com
fitness.riku.ai
games.klujo.com
iludogaming.com
ironcitygym.com
localove.online
marksteward.org
mikestuward.org
projektelco.com
proscale.com.br
ren.hartawan.my
sellmycarbr.com
sniperclass.com
svhmapp.mprs.in
tanjakoil.store
typebot.aloe.do
web.ofilipi.com
acordo-certo.com
app-liberado.pro
ask.pemantau.org
batepapo.digital
bot.contakit.com
bot.imovfast.com
bot.lafabri.link
bot.neobank.tech
bot.piccinato.co
bot.synclab.help
chat.sifucrm.com
tribe.ezbooking.ai
voarmaisbrasil.app
w.onewebcenter.com
web.lordromulo.com
web.pauloaguia.com
www.yellobot.co.za
zap.techadviser.in
zero-pendencia.com
ai.convobuilder.com
ai.digitaldaftar.in
al.onewebcenter.com
albertokouty.com.br
app.danielnalex.com
ask.realversity.org
blazecontrol.com.br
bop.hartanah101.com
bot.boston-voip.com
bot.cabinpromos.com
bot.carnaval.studio
bot.digitalbled.com
bot.dsignagency.com
bot.enthrallart.com
bot.eventhub.com.au
bot.febredojogo.com
bot.gravityatoms.in
bot.jepierre.com.br
bot.jogodoandre.com
bot.jogomoderno.com
bot.ltmidias.com.br
bot.viralsangat.com
bot.winglabs.com.br
bt.scadiagro.com.br
capitaldigital.live
carsalesenquiry.com
casahackeada.online
chat.jubahkonvo.com
chat.marius.digital
chat.mosdent.com.tr
chat.rahsiakami.com
chat.sr7digital.com
chatbot.matthesv.de
chatbot.repplai.com
chatwebandreia.site
co.onewebcenter.com
cr.onewebcenter.com
danielmentality.com
demo.newaiguide.com
demo.wemakebots.xyz
destinyjunior.cloud
feiralimpanomes.com
finalizarseguro.app
guiasairdividas.com

@vercel
Copy link

@vercel vercel bot commented on 5298538 Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 5298538 Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
app.typebot.io
builder-v2-typebot-io.vercel.app

Please sign in to comment.