From d9433cb00fa7e7eef535a671bccf38cb94b864e1 Mon Sep 17 00:00:00 2001 From: Jacky Date: Thu, 31 Oct 2024 17:37:31 +0800 Subject: [PATCH] enhance(main): ignore net.ErrClosed --- .air.toml | 2 +- main.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.air.toml b/.air.toml index 4826f736..8348c359 100644 --- a/.air.toml +++ b/.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 diff --git a/main.go b/main.go index 53034f4c..e9542a9f 100644 --- a/main.go +++ b/main.go @@ -115,8 +115,16 @@ func main() { Run: Program(confPath), Debug: cSettings.ServerSettings.RunMode == gin.DebugMode, 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) { - logger.Fatal(err) + if !errors.Is(err, context.DeadlineExceeded) && + !errors.Is(err, context.Canceled) && + !errors.Is(err, net.ErrClosed) { + logger.Error(err) } }