Clan-app/api: add traceback for all underlying exceptions

This commit is contained in:
Johannes Kirschbauer
2024-11-28 16:26:49 +01:00
parent 17f1f2dca8
commit c35b30a447

View File

@@ -1,5 +1,6 @@
import json import json
import logging import logging
import traceback
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
@@ -107,20 +108,37 @@ class WebExecutor(GObject.Object):
) )
return return
# Initialize dataclasses from the payload try:
reconciled_arguments = {} # Initialize dataclasses from the payload
for k, v in data.items(): reconciled_arguments = {}
# Some functions expect to be called with dataclass instances for k, v in data.items():
# But the js api returns dictionaries. # Some functions expect to be called with dataclass instances
# Introspect the function and create the expected dataclass from dict dynamically # But the js api returns dictionaries.
# Depending on the introspected argument_type # Introspect the function and create the expected dataclass from dict dynamically
arg_class = self.jschema_api.get_method_argtype(method_name, k) # Depending on the introspected argument_type
arg_class = self.jschema_api.get_method_argtype(method_name, k)
# TODO: rename from_dict into something like construct_checked_value # TODO: rename from_dict into something like construct_checked_value
# from_dict really takes Anything and returns an instance of the type/class # from_dict really takes Anything and returns an instance of the type/class
reconciled_arguments[k] = from_dict(arg_class, v) reconciled_arguments[k] = from_dict(arg_class, v)
GLib.idle_add(fn_instance.internal_async_run, reconciled_arguments) GLib.idle_add(fn_instance.internal_async_run, reconciled_arguments)
except Exception as e:
self.return_data_to_js(
method_name,
json.dumps(
{
"op_key": data["op_key"],
"status": "error",
"errors": [
{
"message": "Internal API Error",
"description": traceback.format_exception(e),
}
],
}
),
)
def on_result(self, source: ImplFunc, data: GResult) -> None: def on_result(self, source: ImplFunc, data: GResult) -> None:
result = dataclass_to_dict(data.result) result = dataclass_to_dict(data.result)