chore: improve route not found method (#190)

* chore: improve route not found method

* docs: add feature
This commit is contained in:
Richard
2025-07-03 13:26:20 +08:00
committed by GitHub
parent 0bb806b1d2
commit 5882db2acc
2 changed files with 15 additions and 1 deletions

View File

@@ -3,6 +3,7 @@
## v1.11.0
- chore: improve kakfa component
- chore: improve route not found method
## v1.10.0

View File

@@ -97,7 +97,20 @@ func (r *Response) Error(c *gin.Context, err error) {
// RouteNotFound 未找到相关路由
func RouteNotFound(c *gin.Context) {
c.String(http.StatusNotFound, "the route not found")
accept := c.GetHeader("Accept")
if accept == "" {
accept = c.ContentType()
}
if accept == "application/json" || accept == "application/json; charset=utf-8" {
response := Response{
Code: http.StatusNotFound,
Message: "the route not found",
Data: gin.H{},
}
c.JSON(http.StatusNotFound, response)
} else {
c.String(http.StatusNotFound, "the route not found")
}
}
// healthCheckResponse 健康检查响应结构体