Browse Source

enhance(main): ignore net.ErrClosed

Jacky 11 months ago
parent
commit
4eef0991c4
2 changed files with 10 additions and 5 deletions
  1. 1 1
      .air.toml
  2. 9 4
      main.go

+ 1 - 1
.air.toml

@@ -33,7 +33,7 @@ delay = 1000 # ms
 # Stop running old binary when build errors occur.
 stop_on_error = true
 # Send Interrupt signal before killing process (windows does not support this feature)
-send_interrupt = false
+send_interrupt = true
 # Delay after sending Interrupt signal
 kill_delay = 500 # ms
 

+ 9 - 4
main.go

@@ -75,11 +75,16 @@ func main() {
 	err := risefront.New(ctx, risefront.Config{
 		Run:       Program(confPath),
 		Addresses: []string{fmt.Sprintf("%s:%d", cSettings.ServerSettings.Host, cSettings.ServerSettings.Port)},
+		ErrorHandler: func(kind string, err error) {
+			if errors.Is(err, net.ErrClosed) {
+				return
+			}
+			logger.Error(kind, err)
+		},
 	})
-	if !errors.Is(err, context.DeadlineExceeded) {
-		if !errors.Is(err, net.ErrClosed) {
-			panic(err)
-		}
+	if !errors.Is(err, context.DeadlineExceeded) &&
+		!errors.Is(err, context.Canceled) &&
+		!errors.Is(err, net.ErrClosed) {
 		logger.Error(err)
 	}
 }