🚸 (chatnode) Add proper error message handling
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
import { createAction, option } from '@typebot.io/forge'
|
import { createAction, option } from '@typebot.io/forge'
|
||||||
import { isDefined, isEmpty } from '@typebot.io/lib'
|
import { isDefined, isEmpty } from '@typebot.io/lib'
|
||||||
import { got } from 'got'
|
import { HTTPError, got } from 'got'
|
||||||
import { apiBaseUrl } from '../constants'
|
import { apiBaseUrl } from '../constants'
|
||||||
import { auth } from '../auth'
|
import { auth } from '../auth'
|
||||||
import { ChatNodeResponse } from '../types'
|
import { ChatNodeResponse } from '../types'
|
||||||
@ -36,7 +36,9 @@ export const sendMessage = createAction({
|
|||||||
credentials: { apiKey },
|
credentials: { apiKey },
|
||||||
options: { botId, message, responseMapping, threadId },
|
options: { botId, message, responseMapping, threadId },
|
||||||
variables,
|
variables,
|
||||||
|
logs,
|
||||||
}) => {
|
}) => {
|
||||||
|
try {
|
||||||
const res: ChatNodeResponse = await got
|
const res: ChatNodeResponse = await got
|
||||||
.post(apiBaseUrl + botId, {
|
.post(apiBaseUrl + botId, {
|
||||||
headers: {
|
headers: {
|
||||||
@ -58,6 +60,15 @@ export const sendMessage = createAction({
|
|||||||
if (item === 'Thread ID')
|
if (item === 'Thread ID')
|
||||||
variables.set(mapping.variableId, res.chat_session_id)
|
variables.set(mapping.variableId, res.chat_session_id)
|
||||||
})
|
})
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof HTTPError)
|
||||||
|
return logs.add({
|
||||||
|
status: 'error',
|
||||||
|
description: error.message,
|
||||||
|
details: error.response.body,
|
||||||
|
})
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user