Browse Source

feat:404页面

Roc 1 year ago
parent
commit
b8fbf90281
2 changed files with 25 additions and 0 deletions
  1. 21 0
      controllers/error.go
  2. 4 0
      main.go

+ 21 - 0
controllers/error.go

@@ -0,0 +1,21 @@
+package controllers
+
+import "eta/eta_report/models"
+
+// ErrorController
+// @Description: 该控制器处理页面错误请求
+type ErrorController struct {
+	BaseCommonController
+}
+
+func (c *ErrorController) Error404() {
+	c.Data["content"] = "很抱歉您访问的地址或者方法不存在"
+	//c.TplName = "error/404.html"
+
+	br := new(models.BaseResponse).Init()
+
+	br.Msg = "您访问的资源不存在"
+	br.Ret = 404
+	c.Data["json"] = br
+	c.ServeJSON()
+}

+ 4 - 0
main.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"eta/eta_report/controllers"
 	_ "eta/eta_report/routers"
 	"eta/eta_report/services"
 
@@ -13,5 +14,8 @@ func main() {
 		web.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
 	}
 	go services.InitTask()
+
+	// 异常处理
+	web.ErrorController(&controllers.ErrorController{})
 	web.Run()
 }