HttpResponse.notFound with error message in Micronaut

Viewed 475

I have a simple Rest API where it checks the category id is present or not in the database as below

@Controller("/sub-category")
public class SubCategoryController implements ISubCategoryOperation
{
    @Post
      public Maybe<HttpResponse> post(@Valid SubCategoryViewModel categoryViewModel) {
            LOG.info(String.format("Controller --> Updating the specified category"));
            return iCategoryManager.Count(categoryViewModel.categoryId()).flatMap(item -> {
                if (item > 0) {
                    iSubCategoryManager.Create(categoryViewModel);
                    return Maybe.just(HttpResponse.created(categoryViewModel));
                } else
                    return Maybe.just(HttpResponse.notFound("Category id not found"));
            });
        }
}

In the else statement I am returning a message "Category id not found" in the body of the HTTP, however, I am not able to see the message on the client-side for example on the postman

enter image description here

What I am missing ?

Update 1

The above controller method has been called from API gateway using micronaut declarative client as below

@Controller("/api/${api.version:v1}/sub-category")
public class ApiGatewaySubCategoryController implements ISubCategoryOperation{
    private final ISubCategoryClient iSubCategoryClient;

    public ApiGatewaySubCategoryController(ISubCategoryClient iSubCategoryClient) {
        this.iSubCategoryClient = iSubCategoryClient;
    }

    @Override
    public Maybe<HttpResponse<?>> post(@NotBlank String id, @Valid SubCategoryViewModel model) {
        return this.iSubCategoryClient.post(id, model);
    }
}

declarative HTTP client

@Client(id="feteBirdProduct", path = "/sub-category")
public interface ISubCategoryClient extends ISubCategoryOperation{
}
0 Answers
Related