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
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{
}
question from:
https://stackoverflow.com/questions/65865503/httpresponse-notfound-with-error-message-in-micronaut 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…