error 204 crash the RPC server. changing the 204 error to 404 when data not found

This commit is contained in:
adator
2025-11-23 00:53:03 +01:00
parent b527282bf2
commit 9e688f7964
4 changed files with 6 additions and 4 deletions

View File

@@ -12,12 +12,14 @@ class IRPC:
self.http_status_code = http_status_code
self.response_model = {
"jsonrpc": "2.0",
"method": 'unknown',
"id": 123
}
def reset(self):
self.response_model = {
"jsonrpc": "2.0",
"method": 'unknown',
"id": 123
}

View File

@@ -17,7 +17,7 @@ if TYPE_CHECKING:
class JSonRpcServer:
def __init__(self, context: 'Loader', *, hostname: str = 'localhost', port: int = 5000):
def __init__(self, context: 'Loader', *, hostname: str = '0.0.0.0', port: int = 5000):
self._ctx = context
self.live: bool = False
self.host = hostname
@@ -77,10 +77,10 @@ class JSonRpcServer:
response_data = {
"jsonrpc": "2.0",
"method": method,
"id": request_data.get('id', 123)
}
response_data['method'] = method
rip = request.client.host
rport = request.client.port
http_code = http_status_code.HTTP_200_OK
@@ -89,6 +89,7 @@ class JSonRpcServer:
r: JSONResponse = self.methods[method](**params)
resp = json.loads(r.body)
resp['id'] = request_data.get('id', 123)
resp['method'] = method
return JSONResponse(resp, r.status_code)
response_data['error'] = rpcerr.create_error_response(rpcerr.JSONRPCErrorCode.METHOD_NOT_FOUND)

View File

@@ -1,5 +1,4 @@
from typing import TYPE_CHECKING
from starlette.responses import JSONResponse
from core.classes.interfaces.irpc_endpoint import IRPC
from core.classes.modules.rpc.rpc_errors import JSONRPCErrorCode

View File

@@ -42,4 +42,4 @@ class RPCUser(IRPC):
return JSONResponse(self.response_model)
self.response_model['result'] = 'User not found!'
return JSONResponse(self.response_model, self.http_status_code.HTTP_204_NO_CONTENT)
return JSONResponse(self.response_model, self.http_status_code.HTTP_404_NOT_FOUND)