From 5a108290416f4733b1635d73f05cf7db9ca64f11 Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Wed, 28 May 2025 21:34:08 +0800 Subject: [PATCH] add ErrorUseHandle --- context.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/context.go b/context.go index 4efb57d..69b5073 100644 --- a/context.go +++ b/context.go @@ -437,3 +437,16 @@ func (c *Context) GetReqHeader(key string) string { func (c *Context) GetAllReqHeader() http.Header { return c.Request.Header } + +// 使用定义的errorHandle来处理error并结束当前handle +func (c *Context) ErrorUseHandle(code int) { + if c.engine != nil && c.engine.errorHandle.handler != nil { + c.engine.errorHandle.handler(c, code) + c.Abort() + return + } else { + // Default error handling if no custom handler is set + c.String(code, http.StatusText(code)) + c.Abort() + } +}