feat: 优化错误码

This commit is contained in:
余泓铮
2025-08-05 20:55:58 +08:00
parent 73db0cd124
commit 3c384775f6
3 changed files with 54 additions and 27 deletions
+12 -2
View File
@@ -202,8 +202,13 @@ func (s *DriverSession) RequestWithRetry(method string, urlStr string, rawBody [
synthesizeEventRetryAdded = true
}
// Notice: use DeviceHTTPDriverError when request driver failed
lastError = errors.Wrap(code.DeviceHTTPDriverError, err.Error())
// Check if it's already a DeviceOfflineError
if errors.Is(err, code.DeviceOfflineError) {
lastError = err
} else {
// Use DeviceHTTPDriverError for other errors
lastError = errors.Wrap(code.DeviceHTTPDriverError, err.Error())
}
// If this was the last attempt, break
if attempt == maxRetry {
@@ -294,6 +299,11 @@ func (s *DriverSession) Request(method string, urlStr string, rawBody []byte, op
driverResult.RequestTime = time.Now()
var resp *http.Response
if resp, err = s.client.Do(req); err != nil {
// Check for connection reset or EOF errors and classify as DeviceOfflineError
if strings.Contains(err.Error(), "read: connection reset by peer") ||
strings.Contains(err.Error(), "EOF") {
return nil, errors.Wrap(code.DeviceOfflineError, err.Error())
}
return nil, err
}
defer func() {