Skip to content

[Bug]: HayStackClient treats a non-2xx response as a successful retrieval #4130

Closed

Description

@ningmao-hlyz

Describe the bug

HayStackClient.retrieve logs a non-2xx status and then parses the body anyway. The only failure check after that is code != null && code != successCode, so an error response whose body carries no code field (a gateway 502/503, or a proxy error page that happens to be JSON) comes back to the caller as a successful retrieval with no documents.

To Reproduce

Point a HayStackConfig at an endpoint that answers 503 with {"error": "service unavailable"}, then call client.retrieve("q", null, null).block(). It returns a HayStackResponse with no documents instead of failing.

Relevant code (HayStackClient.retrieve, around line 235):

if (!response.isSuccessful()) {
    logger.error("HayStack API error: status={}, body={}", response.code(), responseBody);
}

HayStackResponse hayStackResponse =
        JsonUtils.getJsonCodec().fromJson(responseBody, HayStackResponse.class);
if (hayStackResponse.getCode() != null
        && !hayStackResponse.getCode().equals(config.getSuccessCode())) {
    throw new HayStackApiException(...);
}
return hayStackResponse;

Expected behavior

A non-2xx status fails the retrieval. The other RAG clients already behave this way: DifyRAGClient throws from handleErrorResponse before parsing.

Error messages

None, which is the problem: the caller sees an empty result and no indication that the upstream call failed.

Environment (please complete the following information):

  • AgentScope-Java Version: 2.1.0-SNAPSHOT (main at 2d70942c)
  • Java Version: 17
  • OS: Windows 11

Additional context

A 200 whose body carries no code field is left alone: it is indistinguishable from a response with no documents, and this report is only about the transport-level signal.

I have a fix and a test ready and will open a PR if this is a real defect.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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