diff --git a/CHANGELOG.md b/CHANGELOG.md index fec5969ca0..cacebc4ece 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## v1.11.0 - chore: improve kakfa component +- chore: improve route not found method ## v1.10.0 diff --git a/pkg/app/response.go b/pkg/app/response.go index 12105db2ee..c08acd0f04 100644 --- a/pkg/app/response.go +++ b/pkg/app/response.go @@ -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 健康检查响应结构体