mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-08 08:57:40 +08:00
add errcode func
This commit is contained in:
@@ -227,3 +227,16 @@ func GetErrorCode(err error) (errCode int) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetErrorByCode(errCode int) (error) {
|
||||||
|
if errCode < 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for key, value := range errorsMap {
|
||||||
|
if value == errCode {
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,3 +10,9 @@ func TestGetErrorCode(t *testing.T) {
|
|||||||
code := GetErrorCode(err)
|
code := GetErrorCode(err)
|
||||||
fmt.Println(code)
|
fmt.Println(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetErrorByCode(t *testing.T) {
|
||||||
|
code := 0
|
||||||
|
err := GetErrorByCode(code)
|
||||||
|
fmt.Println("[TestGetErrorByCode]:err:",err)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user