28 lines
547 B
Go
28 lines
547 B
Go
package checkresult
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net"
|
|
|
|
"mtproxy_checker/internal/checker"
|
|
)
|
|
|
|
// Classify maps a checker error to CLI-style exit codes: 0 OK, 1 generic, 3 proxy closed, 4 timeout.
|
|
func Classify(err error) (exitCode int, message string) {
|
|
if err == nil {
|
|
return 0, ""
|
|
}
|
|
if errors.Is(err, checker.ErrProxyClosed) {
|
|
return 3, err.Error()
|
|
}
|
|
if errors.Is(err, context.DeadlineExceeded) {
|
|
return 4, "timeout"
|
|
}
|
|
var ne net.Error
|
|
if errors.As(err, &ne) && ne.Timeout() {
|
|
return 4, "timeout"
|
|
}
|
|
return 1, err.Error()
|
|
}
|