如何解决HttpResponse.notFound 与 Micronaut 中的错误消息
我有一个简单的 Rest API,用于检查数据库中是否存在类别 ID,如下所示
@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"));
});
}
}
在 else 语句中,我在 HTTP 正文中返回消息 “未找到类别 ID”,但是,我无法在客户端看到该消息,例如邮递员
我缺少什么?
更新 1
使用 micronaut 声明式客户端从 API 网关调用了上述控制器方法,如下所示
@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);
}
}
声明式 HTTP 客户端
@Client(id="feteBirdProduct",path = "/sub-category")
public interface ISubCategoryClient extends ISubCategoryOperation{
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。