3

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{
}
San Jaisy
  • 15,327
  • 34
  • 171
  • 290
  • Is your request hitting `return Maybe.just(HttpResponse.notFound("Category id not found"));` or are you getting a 404 for a different reason? – Jeff Scott Brown Jan 26 '21 at 14:54
  • Have you annotated your controller with @Controller("/api/v1/sub-category")? – AmitB10 Jan 27 '21 at 04:21
  • Yes it is annotated with @controller – San Jaisy Jan 27 '21 at 16:37
  • @JeffScottBrown it is coming to that code, and returning the value, but can't see the value from the client. – San Jaisy Feb 01 '21 at 01:53
  • As @AmitB10 said, your controller is annotated with "/sub-category", but the postman screenshot shows "/api/v1/sub-category". It is unclear without more source code to know if you configured the web root to be different in `application.yaml` or if you are calling this controller from another microservice and that microservice is handling the HTTP/404 with a "Page Not Found". I was able to get the desired response using your code (had to make changes), so would need more code or a reproducer to better understand – Dave Feb 10 '21 at 23:34
  • @Dave added the updated section in the UPDATE 1, please have a look – San Jaisy Feb 11 '21 at 06:28

0 Answers0