微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

覆盖 micronaut

如何解决覆盖 micronaut

我正在尝试覆盖 micronaut 中的 not-found 异常处理程序。

我想抛出我的自定义错误格式,但找不到我要替换的异常处理程序。

我目前的实现:

@Produces
@Singleton
@Requires(classes = {Exception.class,ExceptionHandler.class})
//@Replaces(NotFoundExceptionHandler.class)
public class MyNotFoundExceptionHandler implements ExceptionHandler<Exception,HttpResponse<?>> {
    
    @Override
    public HttpResponse<?> handle(HttpRequest request,Exception exception) {
        return HttpResponse.notFound();
    }

}

认的 micronaut 异常处理程序在 not-found 上抛出此格式:

{
    "message": "Page Not Found","_links": {
        "self": {
            "href": "/api/not-found","templated": false
        }
    }
}

我已经覆盖了其他认异常处理程序,例如 ConstraintExceptionHandlerUnsatisfiedRouteHandler,但是对于 not-found,记录器不会在控制台中打印异常:

20:43:23.863 [default-nioEventLoopGroup-1-5] DEBUG i.m.h.s.netty.RoutingInBoundHandler - Request GET /api/not-found
20:43:23.864 [default-nioEventLoopGroup-1-5] DEBUG i.m.h.s.netty.RoutingInBoundHandler - No matching route: GET /api/not-found
20:43:23.864 [default-nioEventLoopGroup-1-5] DEBUG i.m.web.router.RouteMatchUtils - Route match attribute for request (/api/not-found) not found

有人知道要覆盖哪个异常处理程序吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。