Skip to content

Commit

Permalink
integrates check necessary because api returns 200
Browse files Browse the repository at this point in the history
  • Loading branch information
lakhoune committed Dec 10, 2023
1 parent a0f3353 commit b83d828
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/lib/isErrorResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function isErrorResponse(responseText) {
if (typeof responseText === "string") {
return !responseText.includes("<?xml");
}
return false;
}
29 changes: 25 additions & 4 deletions src/statistics/bot-statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getInstance } from "@rwth-acis/syncmeta-widgets/src/es6/lib/yjs-sync";
import interact from "interactjs";
import "./config-pane.js";
import "./measure-visualization.js";
import { isErrorResponse } from "../lib/isErrorResponse.js";
/**
* @customElement
*
Expand Down Expand Up @@ -219,10 +220,10 @@ class BotStats extends LitElement {
changeView(e) {
if (e.target.value === "petri-net") {
this.loading = true;
this.fetchConversationModel(this.configMap.get("bot-name").toString());
this.fetchConversationModel(this.configMap.get("bot-name")?.toString());
} else {
this.loading = true;
this.fetchBPMNModel(this.configMap.get("bot-name").toString());
this.fetchBPMNModel(this.configMap.get("bot-name")?.toString());
}
}

Expand Down Expand Up @@ -369,6 +370,9 @@ class BotStats extends LitElement {
}

async fetchBPMNModel(botName) {
if (!botName) {
return;
}
document.getElementById("pm-res").querySelector("svg")?.remove();

const botManagerEndpointInput = this.configMap
Expand Down Expand Up @@ -403,6 +407,7 @@ class BotStats extends LitElement {
Accept: "text/html",
},
});

if (!response.ok) {
try {
const body = await response.json();
Expand All @@ -412,12 +417,18 @@ class BotStats extends LitElement {
}
return;
}
const responseText = await response.text();
if (isErrorResponse(responseText)) {
this.alertMessage = `Error from server`;
return;
}

this.loading = false;
const element = document.getElementById("pm-res");

// create a new div and insert the svg into it
const div = document.createElement("div");
div.innerHTML = await response.text();
div.innerHTML = responseText;

document.getElementById("pm-res").appendChild(div);

Expand Down Expand Up @@ -447,6 +458,9 @@ class BotStats extends LitElement {
}

async fetchConversationModel(botName) {
if (!botName) {
return;
}
document.getElementById("pm-res").querySelector("svg")?.remove();
const botManagerEndpointInput = this.configMap
.get("sbm-endpoint")
Expand Down Expand Up @@ -485,6 +499,7 @@ class BotStats extends LitElement {
Accept: "text/html",
},
});

if (!response.ok) {
try {
const body = await response.json();
Expand All @@ -494,11 +509,17 @@ class BotStats extends LitElement {
}
return;
}
const responseText = await response.text();
if (isErrorResponse(responseText)) {
this.alertMessage = `Error from server ${response.status}`;
return;
}

this.loading = false;
const element = document.getElementById("pm-res");
// create a new div and insert the svg into it
const div = document.createElement("div");
div.innerHTML = await response.text();
div.innerHTML = responseText;

document.getElementById("pm-res").appendChild(div);
const svg = document.getElementById("pm-res").querySelector("svg");
Expand Down

0 comments on commit b83d828

Please sign in to comment.