mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 07:57:27 +08:00
feat: 优化错误码
This commit is contained in:
+12
-2
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user