Skip to content

Commit 5882db2

Browse files
authored
chore: improve route not found method (#190)
* chore: improve route not found method * docs: add feature
1 parent 0bb806b commit 5882db2

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## v1.11.0
44

55
- chore: improve kakfa component
6+
- chore: improve route not found method
67

78
## v1.10.0
89

pkg/app/response.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,20 @@ func (r *Response) Error(c *gin.Context, err error) {
9797

9898
// RouteNotFound 未找到相关路由
9999
func RouteNotFound(c *gin.Context) {
100-
c.String(http.StatusNotFound, "the route not found")
100+
accept := c.GetHeader("Accept")
101+
if accept == "" {
102+
accept = c.ContentType()
103+
}
104+
if accept == "application/json" || accept == "application/json; charset=utf-8" {
105+
response := Response{
106+
Code: http.StatusNotFound,
107+
Message: "the route not found",
108+
Data: gin.H{},
109+
}
110+
c.JSON(http.StatusNotFound, response)
111+
} else {
112+
c.String(http.StatusNotFound, "the route not found")
113+
}
101114
}
102115

103116
// healthCheckResponse 健康检查响应结构体

0 commit comments

Comments
 (0)