优化错误处理

This commit is contained in:
M09Ic 2022-11-17 05:53:04 +08:00
parent 7d67e81cb0
commit bfda87826a
2 changed files with 9 additions and 3 deletions

View File

@ -299,7 +299,7 @@ func (p *Pool) BaseCompare(bl *pkg.Baseline) {
if ok { if ok {
if status = base.Compare(bl); status == 1 { if status = base.Compare(bl); status == 1 {
p.PutToInvalid(bl, "compare failed") p.PutToInvalid(bl, ErrCompareFailed.Error())
return return
} }
} }
@ -307,13 +307,13 @@ func (p *Pool) BaseCompare(bl *pkg.Baseline) {
bl.Collect() bl.Collect()
for _, f := range bl.Frameworks { for _, f := range bl.Frameworks {
if f.Tag == "waf/cdn" { if f.Tag == "waf/cdn" {
p.PutToInvalid(bl, "waf") p.PutToInvalid(bl, ErrWaf.Error())
return return
} }
} }
if ok && status == 0 && base.FuzzyCompare(bl) { if ok && status == 0 && base.FuzzyCompare(bl) {
p.PutToInvalid(bl, "fuzzy compare failed") p.PutToInvalid(bl, ErrFuzzyCompareFailed.Error())
p.PutToFuzzy(bl) p.PutToFuzzy(bl)
return return
} }

View File

@ -8,6 +8,8 @@ const (
ErrRequestFailed ErrRequestFailed
ErrWaf ErrWaf
ErrRedirect ErrRedirect
ErrCompareFailed
ErrFuzzyCompareFailed
) )
func (e ErrorType) Error() string { func (e ErrorType) Error() string {
@ -22,6 +24,10 @@ func (e ErrorType) Error() string {
return "maybe ban of waf" return "maybe ban of waf"
case ErrRedirect: case ErrRedirect:
return "duplicate redirect url" return "duplicate redirect url"
case ErrCompareFailed:
return "compare failed"
case ErrFuzzyCompareFailed:
return "fuzzy compare failed"
default: default:
return "unknown error" return "unknown error"
} }