Skip to content

BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr

Handling the situation where the scan log does not exist

lotk84ff44bf31d6
diff --git a/core/internal/controller/abnormal_recipient/abnormal_recipient_v1_get_scan_log.go b/core/internal/controller/abnormal_recipient/abnormal_recipient_v1_get_scan_log.go
index e596e9b9..2f609d60 100644
--- a/core/internal/controller/abnormal_recipient/abnormal_recipient_v1_get_scan_log.go
+++ b/core/internal/controller/abnormal_recipient/abnormal_recipient_v1_get_scan_log.go
@@ -6,29 +6,23 @@ import (
"context"
"github.com/gogf/gf/v2/errors/gerror"
"os"
- "strings"
)
func (c *ControllerV1) GetScanLog(ctx context.Context, req *v1.GetScanLogReq) (res *v1.GetScanLogRes, err error) {
var logDir = public.HostWorkDir + "/logs/core/check_email_valid.txt"
res = &v1.GetScanLogRes{}
+ exists1 := public.FileExists(logDir)
+ if !exists1 {
+ res.Data = ""
+ res.SetSuccess(public.LangCtx(ctx, "Success"))
+ return
+ }
content, err := os.ReadFile(logDir)
if err != nil {
- if os.IsNotExist(err) {
- res.Data = ""
- res.SetSuccess(public.LangCtx(ctx, "Success"))
- return
- }
-
- if strings.Contains(err.Error(), "no such file or directory") {
- res.Data = ""
- res.SetSuccess(public.LangCtx(ctx, "Success"))
- return
- }
- res.SetError(gerror.New(public.LangCtx(ctx, "Failed to read log file: : {}", err.Error())))
- return
+ res.SetError(gerror.New(public.LangCtx(ctx, "Error occurred while reading the scan log: {}", err.Error())))
+ return res, nil
}
res.Data = string(content)