mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix: parse multiple kube-events from stream's chunk
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
34d8fa4c69
commit
de4226a24a
@ -106,7 +106,7 @@ export class KubeWatchApi {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const reader = req.body.getReader();
|
const reader = req.body.getReader();
|
||||||
const handleEvent = this.handleEvent.bind(this);
|
const handleEvent = this.handleStreamEvent.bind(this);
|
||||||
|
|
||||||
this.stream = new ReadableStream({
|
this.stream = new ReadableStream({
|
||||||
start(controller) {
|
start(controller) {
|
||||||
@ -138,17 +138,25 @@ export class KubeWatchApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected handleEvent(eventStreamChunk: Uint8Array) {
|
protected handleStreamEvent(chunk: Uint8Array) {
|
||||||
|
const jsonText = new TextDecoder().decode(chunk);
|
||||||
|
if (!jsonText) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// decoded json might contain multiple kube-events at a time
|
||||||
|
const events = jsonText.split("\n");
|
||||||
|
|
||||||
|
events.forEach(kubeEvent => {
|
||||||
try {
|
try {
|
||||||
const jsonText = new TextDecoder().decode(eventStreamChunk);
|
const message = this.getMessage(JSON.parse(kubeEvent));
|
||||||
const event: IKubeWatchEvent = JSON.parse(jsonText);
|
|
||||||
const message = this.getMessage(event);
|
|
||||||
this.onMessage.emit(message);
|
this.onMessage.emit(message);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.writeLog({
|
this.writeLog({
|
||||||
error: ["failed to parse watch-api event", error]
|
error: ["failed to parse watch-api event", { error, jsonText }]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getMessage(event: IKubeWatchEvent): IKubeWatchMessage {
|
protected getMessage(event: IKubeWatchEvent): IKubeWatchMessage {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user