handle action error on UI

* update call plugin action utils in order to handle and retrieve on UI exception
This commit is contained in:
Jordan Blasenhauer 2024-04-18 12:54:37 +02:00
parent e0d2ff75fc
commit 32ba33312f
2 changed files with 26 additions and 0 deletions

View file

@ -330,6 +330,7 @@ def run_action(plugin: str, function_name: str = ""):
if tmp_dir:
sys_path.pop()
rmtree(tmp_dir, ignore_errors=True)
app.logger.exception("An error occurred while importing the plugin")
return {"status": "ko", "code": 500, "message": "An error occurred while importing the plugin, see logs for more details"}
@ -359,6 +360,7 @@ def run_action(plugin: str, function_name: str = ""):
sys_path.pop()
rmtree(tmp_dir, ignore_errors=True)
app.logger.exception(message)
if message or not isinstance(res, dict) and not res:
return {"status": "ko", "code": 500, "message": message or "The plugin did not return a valid response"}

View file

@ -82,6 +82,30 @@ class Ping {
// Key of fetch data need to match key of this.data
updateEl(data) {
// Show error
if (data?.error) {
const error = data?.error || "Action exception, no details available";
console.log(error);
// Remove previous data-action-error
const prevError = document.querySelectorAll("[data-action-error]");
if (prevError.length) prevError.forEach((el) => el.remove());
// Add this one
const error_html = `<div data-action-error class="core-layout-separator"></div>
<div data-action-error class="my-2 flex justify-center col-span-12">
<div class="mr-1">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 stroke-red-500 fill-white">
<path stroke-linecap="round" stroke-linejoin="round" d="m9.75 9.75 4.5 4.5m0-4.5-4.5 4.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
</svg>
</div>
<p class="px-1 text-white break-words">(Action error) ${error}</p>
</div>
`;
// add HTML at the end of .core-layout
document
.querySelector("div.core-layout")
.insertAdjacentHTML("beforeend", error_html);
}
try {
const successValues = [
"success",