From f8f1c1da28e1dea03b5b9968c1268253e586a84c Mon Sep 17 00:00:00 2001
From: DeathwingTheBoss <ozcanbarisucar@gmail.com>
Date: Fri, 24 Mar 2023 17:59:40 +0300
Subject: [PATCH] - Update README.md - Update error codes. - Update response
 structure.

---
 Cargo.toml  |  2 +-
 README.md   |  1 +
 src/main.rs | 14 +++++++-------
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 71d0c8d..a5ae3a0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,4 +16,4 @@ lru_time_cache = "0.11.11"
 humantime = "2.1.0"
 config = "0.13.3"
 serde_with = "2.3.1"
-actix-cors = "0.6.4"
\ No newline at end of file
+actix-cors = "0.6.4"
diff --git a/README.md b/README.md
index 17f4267..fea552f 100644
--- a/README.md
+++ b/README.md
@@ -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.
 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.
+ACTIX_CONNECTION_THREADS: Specifies the number of HTTP connections kept alive (default: 8).
 ```
 
 ## Usage
diff --git a/src/main.rs b/src/main.rs
index 2ff6b2a..b4cce06 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -171,9 +171,9 @@ async fn handle_request(
         // build result with data from cache and response
         let result = cached_call.clone();
         return Ok(APICallResponse {
-            id: request.id,
             jsonrpc: request.jsonrpc.clone(),
             result: result["result"].clone(),
+            id: request.id,
             cached: true,
         });
     }
@@ -208,7 +208,7 @@ async fn handle_request(
         Ok(parsed) => parsed,
         Err(err) => {
             return Err(ErrorStructure {
-                code: 3000,
+                code: -32602,
                 message: format!("Unable to parse endpoint data."),
                 error: ErrorField::Message(err.to_string()),
             })
@@ -216,7 +216,7 @@ async fn handle_request(
     };
     if json_body["error"].is_object() {
         return Err(ErrorStructure {
-            code: -32602,
+            code: -32700,
             message: format!("Endpoint returned an error."),
             error: ErrorField::Object(json_body["error"].clone()),
         });
@@ -236,9 +236,9 @@ async fn handle_request(
             .insert(request.params.to_string(), json_body.clone());
     }
     Ok(APICallResponse {
-        id: request.id,
         jsonrpc: request.jsonrpc.clone(),
         result: json_body["result"].clone(),
+        id: request.id,
         cached: false,
     })
 }
@@ -288,8 +288,8 @@ async fn api_call(
             if requests.len() > 100 {
                 return HttpResponse::InternalServerError().json(ErrorStructure {
                     code: -32600,
-                    message: "Internal Server Error".to_string(),
-                    error: ErrorField::Message("Batch size too large.".to_string()),
+                    message: "Request parameter error.".to_string(),
+                    error: ErrorField::Message("Batch size too large, maximum allowed is 100.".to_string()),
                 });
             }
             
@@ -307,9 +307,9 @@ async fn api_call(
                     cached = false;
                 }
                 result.push(serde_json::json!({
-                    "id": response.id,
                     "jsonrpc": response.jsonrpc,
                     "result": response.result,
+                    "id": response.id,
                 }));
             }
             HttpResponse::Ok()
-- 
GitLab