Skip to content
Snippets Groups Projects
Commit f8f1c1da authored by DeathwingTheBoss's avatar DeathwingTheBoss
Browse files

- Update README.md

- Update error codes.
- Update response structure.
parent ab1a57d9
No related branches found
No related tags found
No related merge requests found
...@@ -16,4 +16,4 @@ lru_time_cache = "0.11.11" ...@@ -16,4 +16,4 @@ lru_time_cache = "0.11.11"
humantime = "2.1.0" humantime = "2.1.0"
config = "0.13.3" config = "0.13.3"
serde_with = "2.3.1" serde_with = "2.3.1"
actix-cors = "0.6.4" actix-cors = "0.6.4"
\ No newline at end of file
...@@ -46,6 +46,7 @@ OPERATOR_MESSAGE: Customizable message from the operator (default: "Drone by Dea ...@@ -46,6 +46,7 @@ OPERATOR_MESSAGE: Customizable message from the operator (default: "Drone by Dea
HAF_ENDPOINT: HAF Endpoint that Drone can connect to relay HAF related API calls. HAF_ENDPOINT: HAF Endpoint that Drone can connect to relay HAF related API calls.
HAFAH_ENDPOINT: HAFAH Endpoint that Drone can connect to relay HAFAH related API calls. HAFAH_ENDPOINT: HAFAH Endpoint that Drone can connect to relay HAFAH related API calls.
HIVEMIND_ENDPOINT: Hivemind Endpoint that Drone can connect to relay Hivemind related API calls. HIVEMIND_ENDPOINT: Hivemind Endpoint that Drone can connect to relay Hivemind related API calls.
ACTIX_CONNECTION_THREADS: Specifies the number of HTTP connections kept alive (default: 8).
``` ```
## Usage ## Usage
......
...@@ -171,9 +171,9 @@ async fn handle_request( ...@@ -171,9 +171,9 @@ async fn handle_request(
// build result with data from cache and response // build result with data from cache and response
let result = cached_call.clone(); let result = cached_call.clone();
return Ok(APICallResponse { return Ok(APICallResponse {
id: request.id,
jsonrpc: request.jsonrpc.clone(), jsonrpc: request.jsonrpc.clone(),
result: result["result"].clone(), result: result["result"].clone(),
id: request.id,
cached: true, cached: true,
}); });
} }
...@@ -208,7 +208,7 @@ async fn handle_request( ...@@ -208,7 +208,7 @@ async fn handle_request(
Ok(parsed) => parsed, Ok(parsed) => parsed,
Err(err) => { Err(err) => {
return Err(ErrorStructure { return Err(ErrorStructure {
code: 3000, code: -32602,
message: format!("Unable to parse endpoint data."), message: format!("Unable to parse endpoint data."),
error: ErrorField::Message(err.to_string()), error: ErrorField::Message(err.to_string()),
}) })
...@@ -216,7 +216,7 @@ async fn handle_request( ...@@ -216,7 +216,7 @@ async fn handle_request(
}; };
if json_body["error"].is_object() { if json_body["error"].is_object() {
return Err(ErrorStructure { return Err(ErrorStructure {
code: -32602, code: -32700,
message: format!("Endpoint returned an error."), message: format!("Endpoint returned an error."),
error: ErrorField::Object(json_body["error"].clone()), error: ErrorField::Object(json_body["error"].clone()),
}); });
...@@ -236,9 +236,9 @@ async fn handle_request( ...@@ -236,9 +236,9 @@ async fn handle_request(
.insert(request.params.to_string(), json_body.clone()); .insert(request.params.to_string(), json_body.clone());
} }
Ok(APICallResponse { Ok(APICallResponse {
id: request.id,
jsonrpc: request.jsonrpc.clone(), jsonrpc: request.jsonrpc.clone(),
result: json_body["result"].clone(), result: json_body["result"].clone(),
id: request.id,
cached: false, cached: false,
}) })
} }
...@@ -288,8 +288,8 @@ async fn api_call( ...@@ -288,8 +288,8 @@ async fn api_call(
if requests.len() > 100 { if requests.len() > 100 {
return HttpResponse::InternalServerError().json(ErrorStructure { return HttpResponse::InternalServerError().json(ErrorStructure {
code: -32600, code: -32600,
message: "Internal Server Error".to_string(), message: "Request parameter error.".to_string(),
error: ErrorField::Message("Batch size too large.".to_string()), error: ErrorField::Message("Batch size too large, maximum allowed is 100.".to_string()),
}); });
} }
...@@ -307,9 +307,9 @@ async fn api_call( ...@@ -307,9 +307,9 @@ async fn api_call(
cached = false; cached = false;
} }
result.push(serde_json::json!({ result.push(serde_json::json!({
"id": response.id,
"jsonrpc": response.jsonrpc, "jsonrpc": response.jsonrpc,
"result": response.result, "result": response.result,
"id": response.id,
})); }));
} }
HttpResponse::Ok() HttpResponse::Ok()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment