| 74 | } |
| 75 | |
| 76 | export function getInsightOrError<InsightName extends keyof Trace.Insights.Types.InsightModels>( |
| 77 | insightName: InsightName, insights: Trace.Insights.Types.TraceInsightSets, |
| 78 | navigation?: Trace.Types.Events.NavigationStart): NonNullable<Trace.Insights.Types.InsightModels[InsightName]> { |
| 79 | const insightSet = getInsightSetOrError(insights, navigation); |
| 80 | const insight = insightSet.model[insightName]; |
| 81 | const error = insightSet.modelErrors[insightName]; |
| 82 | if (error) { |
| 83 | // eslint-disable-next-line @typescript-eslint/only-throw-error |
| 84 | throw error; |
| 85 | } |
| 86 | if (!insight) { |
| 87 | throw new Error('missing insight'); |
| 88 | } |
| 89 | |
| 90 | return insight; |
| 91 | } |
| 92 | |
| 93 | export function getFirstOrError<T>(iterator: IterableIterator<T>): T { |
| 94 | const result = iterator.next(); |