App: API return errors to js on invalid api methods
This commit is contained in:
@@ -124,6 +124,9 @@ class GObjApi:
|
|||||||
msg = f"Overwritten method '{m_name}' has different signature than the implementation"
|
msg = f"Overwritten method '{m_name}' has different signature than the implementation"
|
||||||
raise ClanError(msg)
|
raise ClanError(msg)
|
||||||
|
|
||||||
|
def has_obj(self, fn_name: str) -> bool:
|
||||||
|
return fn_name in self._obj_registry or fn_name in self._methods
|
||||||
|
|
||||||
def get_obj(self, fn_name: str) -> type[ImplFunc]:
|
def get_obj(self, fn_name: str) -> type[ImplFunc]:
|
||||||
result = self._obj_registry.get(fn_name, None)
|
result = self._obj_registry.get(fn_name, None)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
|
|||||||
@@ -86,8 +86,27 @@ class WebExecutor(GObject.Object):
|
|||||||
log.debug(f"Webview Request: {json_msg}")
|
log.debug(f"Webview Request: {json_msg}")
|
||||||
payload = json.loads(json_msg)
|
payload = json.loads(json_msg)
|
||||||
method_name = payload["method"]
|
method_name = payload["method"]
|
||||||
|
data = payload.get("data")
|
||||||
|
|
||||||
# Get the function gobject from the api
|
# Get the function gobject from the api
|
||||||
|
if not self.api.has_obj(method_name):
|
||||||
|
self.return_data_to_js(
|
||||||
|
method_name,
|
||||||
|
json.dumps(
|
||||||
|
{
|
||||||
|
"op_key": data["op_key"],
|
||||||
|
"status": "error",
|
||||||
|
"errors": [
|
||||||
|
{
|
||||||
|
"message": "Internal API Error",
|
||||||
|
"description": f"Function '{method_name}' not found",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
function_obj = self.api.get_obj(method_name)
|
function_obj = self.api.get_obj(method_name)
|
||||||
|
|
||||||
# Create an instance of the function gobject
|
# Create an instance of the function gobject
|
||||||
@@ -95,7 +114,6 @@ class WebExecutor(GObject.Object):
|
|||||||
fn_instance.await_result(self.on_result)
|
fn_instance.await_result(self.on_result)
|
||||||
|
|
||||||
# Extract the data from the payload
|
# Extract the data from the payload
|
||||||
data = payload.get("data")
|
|
||||||
if data is None:
|
if data is None:
|
||||||
log.error(
|
log.error(
|
||||||
f"JS function call '{method_name}' has no data field. Skipping execution."
|
f"JS function call '{method_name}' has no data field. Skipping execution."
|
||||||
|
|||||||
Reference in New Issue
Block a user