mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 11:14:23 +00:00
error 204 crash the RPC server. changing the 204 error to 404 when data not found
This commit is contained in:
@@ -12,12 +12,14 @@ class IRPC:
|
|||||||
self.http_status_code = http_status_code
|
self.http_status_code = http_status_code
|
||||||
self.response_model = {
|
self.response_model = {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
|
"method": 'unknown',
|
||||||
"id": 123
|
"id": 123
|
||||||
}
|
}
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.response_model = {
|
self.response_model = {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
|
"method": 'unknown',
|
||||||
"id": 123
|
"id": 123
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
class JSonRpcServer:
|
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._ctx = context
|
||||||
self.live: bool = False
|
self.live: bool = False
|
||||||
self.host = hostname
|
self.host = hostname
|
||||||
@@ -77,10 +77,10 @@ class JSonRpcServer:
|
|||||||
|
|
||||||
response_data = {
|
response_data = {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
|
"method": method,
|
||||||
"id": request_data.get('id', 123)
|
"id": request_data.get('id', 123)
|
||||||
}
|
}
|
||||||
|
|
||||||
response_data['method'] = method
|
|
||||||
rip = request.client.host
|
rip = request.client.host
|
||||||
rport = request.client.port
|
rport = request.client.port
|
||||||
http_code = http_status_code.HTTP_200_OK
|
http_code = http_status_code.HTTP_200_OK
|
||||||
@@ -89,6 +89,7 @@ class JSonRpcServer:
|
|||||||
r: JSONResponse = self.methods[method](**params)
|
r: JSONResponse = self.methods[method](**params)
|
||||||
resp = json.loads(r.body)
|
resp = json.loads(r.body)
|
||||||
resp['id'] = request_data.get('id', 123)
|
resp['id'] = request_data.get('id', 123)
|
||||||
|
resp['method'] = method
|
||||||
return JSONResponse(resp, r.status_code)
|
return JSONResponse(resp, r.status_code)
|
||||||
|
|
||||||
response_data['error'] = rpcerr.create_error_response(rpcerr.JSONRPCErrorCode.METHOD_NOT_FOUND)
|
response_data['error'] = rpcerr.create_error_response(rpcerr.JSONRPCErrorCode.METHOD_NOT_FOUND)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from starlette.responses import JSONResponse
|
from starlette.responses import JSONResponse
|
||||||
from core.classes.interfaces.irpc_endpoint import IRPC
|
from core.classes.interfaces.irpc_endpoint import IRPC
|
||||||
from core.classes.modules.rpc.rpc_errors import JSONRPCErrorCode
|
from core.classes.modules.rpc.rpc_errors import JSONRPCErrorCode
|
||||||
|
|||||||
@@ -42,4 +42,4 @@ class RPCUser(IRPC):
|
|||||||
return JSONResponse(self.response_model)
|
return JSONResponse(self.response_model)
|
||||||
|
|
||||||
self.response_model['result'] = 'User not found!'
|
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)
|
||||||
Reference in New Issue
Block a user