Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

java - HttpResponse.notFound with error message in Micronaut

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{
}
question from:https://stackoverflow.com/questions/65865503/httpresponse-notfound-with-error-message-in-micronaut

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...