gf
gf copied to clipboard
how to capture a Not Allowed method error
当定义了一个路由,method限制为GET,如果使用其他方式访问,比如POST,会输出Forbidden。 因为想要用一个统一的错误页面来展示错误信息,包括panic、其他400以上的status代码、以及这个MethodNotAllowed 。
尝试过使用中间件来实现,用自带的后置中间件ghttp.MiddlewareHandlerResponse,还是自己改写的前置中间件,都无法捕捉到这个Forbidden。 请问如何实现?
另外,用过其他框架,比如fiber,它有个默认的错误处理controller,所有的错误、异常都会用这个controller展示,并且可以自定义这个controller。那么gf能不能也实现这个
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
When a route is defined, the method is limited to GET. If accessed using other methods, such as POST, Forbidden will be output. Because I want to use a unified error page to display error information, including panic, other status codes of more than 400, and this MethodNotAllowed.
I have tried to use middleware to implement it, whether using the built-in post-middleware ghttp.MiddlewareHandlerResponse or the pre-middleware I rewrote, but I can't catch this Forbidden. How to achieve this?
In addition, I have used other frameworks, such as fiber, which has a default error handling controller. All errors and exceptions will be displayed using this controller, and this controller can be customized. So can gf also achieve this?
Hello @l12ab. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it! 你好 @l12ab。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。