fix: better graphql handler #40

Merged
TakahashiNguyen merged 1 commits from fix-better-graphql-error into main 2026-04-28 16:48:40 +00:00
@@ -2,11 +2,14 @@ package com.drinkool.controller;
import com.drinkool.dtos.GraphqlDto;
import io.smallrye.graphql.client.GraphQLClient;
import io.smallrye.graphql.client.GraphQLError;
import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
@Path("/api/eatery")
public class EateryController {
@@ -24,9 +27,13 @@ public class EateryController {
);
if (response.hasError()) {
return jakarta.ws.rs.core.Response.status(500)
.entity(response.getErrors())
.build();
List<String> errorMessages = response
.getErrors()
.stream()
.map(GraphQLError::getMessage)
.collect(Collectors.toList());
return Response.status(400).entity(errorMessages).build();
}
return jakarta.ws.rs.core.Response.ok(