2
0

🚸 (sheets) Show info log instead of error when no rows are found

This commit is contained in:
Baptiste Arnaud
2023-06-15 14:42:20 +02:00
parent b89da5b30a
commit fbe63aa3f3
7 changed files with 32 additions and 13 deletions

View File

@ -23,11 +23,14 @@ export const WebPreview = () => {
details: log.details details: log.details
? { ? {
lang: 'json', lang: 'json',
content: JSON.stringify(log.details, null, 2), content:
typeof log.details === 'string'
? log.details
: JSON.stringify(log.details, null, 2),
} }
: undefined, : undefined,
}) })
console.error(log) if (log.status === 'error') console.error(log)
}) })
} }

View File

@ -11,6 +11,7 @@ import { saveErrorLog } from '@/features/logs/saveErrorLog'
import { updateVariables } from '@/features/variables/updateVariables' import { updateVariables } from '@/features/variables/updateVariables'
import { deepParseVariables } from '@/features/variables/deepParseVariable' import { deepParseVariables } from '@/features/variables/deepParseVariable'
import { matchFilter } from './helpers/matchFilter' import { matchFilter } from './helpers/matchFilter'
import { saveInfoLog } from '@/features/logs/saveInfoLog'
export const getRow = async ( export const getRow = async (
state: SessionState, state: SessionState,
@ -48,10 +49,11 @@ export const getRow = async (
) )
if (filteredRows.length === 0) { if (filteredRows.length === 0) {
log = { log = {
status: 'error', status: 'info',
description: `Couldn't find any rows matching the filter`, description: `Couldn't find any rows matching the filter`,
details: JSON.stringify(filter, null, 2),
} }
await saveErrorLog({ await saveInfoLog({
resultId, resultId,
message: log.description, message: log.description,
}) })

View File

@ -10,6 +10,7 @@ import { ExecuteIntegrationResponse } from '@/features/chat/types'
import { saveErrorLog } from '@/features/logs/saveErrorLog' import { saveErrorLog } from '@/features/logs/saveErrorLog'
import { saveSuccessLog } from '@/features/logs/saveSuccessLog' import { saveSuccessLog } from '@/features/logs/saveSuccessLog'
import { matchFilter } from './helpers/matchFilter' import { matchFilter } from './helpers/matchFilter'
import { saveInfoLog } from '@/features/logs/saveInfoLog'
export const updateRow = async ( export const updateRow = async (
{ result, typebot: { variables } }: SessionState, { result, typebot: { variables } }: SessionState,
@ -42,12 +43,12 @@ export const updateRow = async (
) )
if (filteredRows.length === 0) { if (filteredRows.length === 0) {
log = { log = {
status: 'error', status: 'info',
description: `Could not find any row that matches the filter`, description: `Could not find any row that matches the filter`,
details: JSON.stringify(filter, null, 2), details: JSON.stringify(filter, null, 2),
} }
result && result &&
(await saveErrorLog({ (await saveInfoLog({
resultId: result.id, resultId: result.id,
message: log.description, message: log.description,
details: log.details, details: log.details,

View File

@ -8,4 +8,4 @@ export const saveErrorLog = ({
resultId: string | undefined resultId: string | undefined
message: string message: string
details?: unknown details?: unknown
}) => saveLog('error', resultId, message, details) }) => saveLog({ status: 'error', resultId, message, details })

View File

@ -0,0 +1,11 @@
import { saveLog } from './saveLog'
export const saveInfoLog = ({
resultId,
message,
details,
}: {
resultId: string | undefined
message: string
details?: unknown
}) => saveLog({ status: 'info', resultId, message, details })

View File

@ -1,12 +1,14 @@
import prisma from '@/lib/prisma' import prisma from '@/lib/prisma'
import { isNotDefined } from '@typebot.io/lib' import { isNotDefined } from '@typebot.io/lib'
export const saveLog = ( type Props = {
status: 'error' | 'success', status: 'error' | 'success' | 'info'
resultId: string | undefined, resultId: string | undefined
message: string, message: string
details?: unknown details?: unknown
) => { }
export const saveLog = ({ status, resultId, message, details }: Props) => {
if (!resultId || resultId === 'undefined') return if (!resultId || resultId === 'undefined') return
return prisma.log.create({ return prisma.log.create({
data: { data: {

View File

@ -8,4 +8,4 @@ export const saveSuccessLog = ({
resultId: string | undefined resultId: string | undefined
message: string message: string
details?: unknown details?: unknown
}) => saveLog('success', resultId, message, details) }) => saveLog({ status: 'success', resultId, message, details })