[Logs UI] Avoid a crash when a highlight term doesn't exist (#67332)
This commit is contained in:
parent
16a51a18f8
commit
b7e393dffb
|
@ -51,11 +51,18 @@ export type LogEntriesHighlightsRequest = rt.TypeOf<typeof logEntriesHighlightsR
|
|||
|
||||
export const logEntriesHighlightsResponseRT = rt.type({
|
||||
data: rt.array(
|
||||
rt.union([
|
||||
rt.type({
|
||||
topCursor: rt.null,
|
||||
bottomCursor: rt.null,
|
||||
entries: rt.array(logEntryRT),
|
||||
}),
|
||||
rt.type({
|
||||
topCursor: logEntriesCursorRT,
|
||||
bottomCursor: logEntriesCursorRT,
|
||||
entries: rt.array(logEntryRT),
|
||||
})
|
||||
}),
|
||||
])
|
||||
),
|
||||
});
|
||||
|
||||
|
|
|
@ -79,11 +79,21 @@ export const initLogEntriesHighlightsRoute = ({ framework, logEntries }: InfraBa
|
|||
|
||||
return response.ok({
|
||||
body: logEntriesHighlightsResponseRT.encode({
|
||||
data: entriesPerHighlightTerm.map((entries) => ({
|
||||
data: entriesPerHighlightTerm.map((entries) => {
|
||||
if (entries.length > 0) {
|
||||
return {
|
||||
entries,
|
||||
topCursor: entries[0].cursor,
|
||||
bottomCursor: entries[entries.length - 1].cursor,
|
||||
})),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
entries,
|
||||
topCursor: null,
|
||||
bottomCursor: null,
|
||||
};
|
||||
}
|
||||
}),
|
||||
}),
|
||||
});
|
||||
} catch (error) {
|
||||
|
|
|
@ -46,6 +46,34 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
before(() => esArchiver.load('empty_kibana'));
|
||||
after(() => esArchiver.unload('empty_kibana'));
|
||||
|
||||
it('Handles empty responses', async () => {
|
||||
const { body } = await supertest
|
||||
.post(LOG_ENTRIES_HIGHLIGHTS_PATH)
|
||||
.set(COMMON_HEADERS)
|
||||
.send(
|
||||
logEntriesHighlightsRequestRT.encode({
|
||||
sourceId: 'default',
|
||||
startTimestamp: KEY_BEFORE_START.time,
|
||||
endTimestamp: KEY_AFTER_END.time,
|
||||
highlightTerms: ['some string that does not exist'],
|
||||
})
|
||||
)
|
||||
.expect(200);
|
||||
|
||||
const logEntriesHighlightsResponse = pipe(
|
||||
logEntriesHighlightsResponseRT.decode(body),
|
||||
fold(throwErrors(createPlainError), identity)
|
||||
);
|
||||
|
||||
expect(logEntriesHighlightsResponse.data).to.have.length(1);
|
||||
|
||||
const data = logEntriesHighlightsResponse.data[0];
|
||||
|
||||
expect(data.entries).to.have.length(0);
|
||||
expect(data.topCursor).to.be(null);
|
||||
expect(data.bottomCursor).to.be(null);
|
||||
});
|
||||
|
||||
it('highlights built-in message column', async () => {
|
||||
const { body } = await supertest
|
||||
.post(LOG_ENTRIES_HIGHLIGHTS_PATH)
|
||||
|
|
Loading…
Reference in a new issue