Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.1 KB
Raw Blame
export function getApiErrorDetail(error: unknown): string | undefined {
    if (error !== null && typeof error === 'object') {
        if ('detail' in error && typeof error.detail === 'string') {
            return error.detail
        }

        if ('data' in error && error.data && typeof error.data === 'object') {
            for (const value of Object.values(error.data as Record<string, unknown>)) {
                if (Array.isArray(value) && typeof value[0] === 'string') {
                    return value[0]
                }

                if (typeof value === 'string') {
                    return value
                }
            }
        }
    }

    return undefined
}

export function parseTraceIdsInput(value: string): string[] {
    const dedupedTraceIds = new Set<string>()

    for (const traceId of value
        .split(/[\s,]+/)
        .map((part) => part.trim())
        .filter(Boolean)) {
        dedupedTraceIds.add(traceId)
    }

    return [...dedupedTraceIds]
}

export function formatTraceIdsInput(traceIds: string[]): string {
    return traceIds.join('\n')
}