Browse Source

feat:404页面

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

+ 21 - 0
controllers/error.go

@@ -0,0 +1,21 @@
+package controllers
+
+import "eta/eta_api/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()
+}

+ 6 - 1
main.go

@@ -1,8 +1,9 @@
 package main
 
 import (
-	"fmt"
+	"eta/eta_api/controllers"
 	"eta/eta_api/services/alarm_msg"
+	"fmt"
 	"runtime"
 	"time"
 
@@ -21,6 +22,10 @@ func main() {
 		web.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
 	}
 	go services.Task()
+
+	// 异常处理
+	web.ErrorController(&controllers.ErrorController{})
+
 	web.BConfig.RecoverFunc = Recover
 	web.Run()
 }