Skip to content

Add HTTP Status Code Check in RPC Call #39

@ametel01

Description

@ametel01

Ok(response) => response,

Description:
The current implementation of make_rpc_call does not verify the HTTP status code after receiving a response. This may result in processing error responses (e.g., 4xx or 5xx statuses) as if they were successful, leading to misleading error handling and deserialization issues.

Steps to Reproduce:

  1. Call the RPC endpoint with conditions that force an error HTTP status (e.g., simulate a 500 Internal Server Error).
  2. Observe that the code proceeds to attempt deserialization without checking the response status.

Expected Behavior:

  • The function should verify that the HTTP response status is successful (e.g., using response.status().is_success()) before processing the body.
  • In case of a non-success status, the function should log the error and return an appropriate error message.

Proposed Fix:
Modify the make_rpc_call function to include a check on the HTTP response status. For example:

let raw_response = match raw_response {
    Ok(response) => {
        if !response.status().is_success() {
            error!("Received unsuccessful HTTP status: {:?}", response.status());
            return Err(eyre!("Unsuccessful HTTP response status: {:?}", response.status()));
        }
        response
    }
    Err(e) => {
        error!("HTTP request error: {:?}", e);
        return Err(e.into());
    }
};

Impact:
Implementing this change will improve error handling and prevent the misinterpretation of error responses, leading to more robust and predictable behavior when interacting with the RPC service.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions