-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSE RESTEasy Reactive if an error occurs, cannot retrieve the body #38325
Comments
/cc @FroMage (resteasy-reactive), @geoand (resteasy-reactive), @stuartwdouglas (resteasy-reactive) |
What version of Quarkus are you using? |
@geoand I'm using the version 3.6.6 |
Thanks. Can you share what approxitely the data looks like and what class you trying to deserialize it to? I am just trying to get a more complete understanding of the problem you are facing. |
In case you are tying to use SSE for consuming the OpenAI APIs, you are in luck - have a loot at our langchain4j extension which already provides all you need. If you really want to see how things have been implemented on the SSE side, check out this. |
I have a service A that calls a service B that calls the SSE endpoint via the interface C. The way below. service A : Multi<ChatMessagesSseResponse> chatMessageResponse = this.proxyChatMessageResource.callChat(chatMessageRequest)
.onItem()
.transform(res -> {
ChatMessagesSseResponse chatMessagesSseResponse = new ChatMessagesSseResponse();
try {
if (!res.contains("[DONE]")) {
ChatMessagesAzureSseResponse chatMessagesResponse = objectMapper.readValue(res, ChatMessagesAzureSseResponse.class);
if (chatMessagesResponse.choices().get(0).delta().content() != null && chatMessagesResponse.id() != null) {
chatMessagesSseResponse = new ChatMessagesSseResponse(chatMessagesResponse);
}
}
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return chatMessagesSseResponse;
})
.onFailure().invoke(t ->
logger.info(String.format("Oh no! We received a failure: %s",
t.getMessage())));
return chatMessageResponse
.select().where(message -> message.getId() != null);
} service B : @RestClient
AzureOpenAiApi apiAzure;
public Multi<String> callChat(ChatMessagesAzureRequest chatMessageRequest) {
logger.info("callChat External API");
return this.apiAzure.processGenerativeAIWithChatMessageSse(this.apiKey,
this.deploymentId,
this.apiVersion,
chatMessageRequest)
.onFailure().invoke(t ->
logger.info(String.format("Oh no! We received a failure: %s",
t.getMessage()))
);
} interface C : @RegisterRestClient(configKey = "azure-api")
@RegisterProvider(WebApplicationExceptionRequestFilter.class)
@RegisterProvider(ResponseContainerRequestFilter.class)
@Path("/openai/deployments")
public interface AzureOpenAiApi {
@POST
@Path("/{deploymentId}/chat/completions")
@RestStreamElementType(MediaType.APPLICATION_JSON)
Multi<String> processGenerativeAIWithChatMessageSse(@HeaderParam("api-key") String apiKey,
@PathParam("deploymentId") String deploymentId,
@QueryParam("api-version") String apiVersion,
ChatMessagesAzureRequest chatMessagesAzureRequest); |
See my comment above :). Moreoever, the missing piece from your code is likely this. |
Hi, thanks for example of code @geoand |
What does the body of an |
{
"error": {
"message": "The response was filtered due to the prompt triggering Azure OpenAI's content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766",
"type": null,
"param": "prompt",
"code": "content_filter",
"status": 400
}
} |
I'll have a look some time this week |
I have to identify what kind of error it is. I precise that I can't read the body only on SSE error, with classic API response I can , unfortunately it is not my usecase :-(. Thx for your feedback @geoand |
#38369 fixes the problem |
Ensure that response body of unsuccessful SSE request can be read
Fixes: quarkusio#38325 (cherry picked from commit e2668c5)
Fixes: quarkusio#38325 (cherry picked from commit e2668c5)
Describe the bug
My Quarkus application is a client that calls a Server-Sent Event (SSE) endpoint. I followed the recommendations of the documentation specific to SSE. It works as long as there is no error.
If an error occured, RESTEasy Reactive throws a WebApplicationException. I have register an exceptionMapper and a ClientExceptionMapper to catch the Response object. It works but I have to read the body of the error response 400 to do specific stuffs
Unfortunately, the entity or streamEntity return allways null.
How manage this kind of usecase ?
Expected behavior
a way to retrieve the body error
Actual behavior
No response
How to Reproduce?
No response
Output of
uname -a
orver
No response
Output of
java -version
No response
Quarkus version or git rev
3.6.6
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
No response
The text was updated successfully, but these errors were encountered: