forked from go-rod/rod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
54 lines (45 loc) · 1.08 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package rod
import "fmt"
// ErrCode for errors
type ErrCode string
const (
// ErrExpectElement error code
ErrExpectElement ErrCode = "expect js to return an element"
// ErrExpectElements error code
ErrExpectElements ErrCode = "expect js to return an array of elements"
// ErrElementNotFound error code
ErrElementNotFound ErrCode = "cannot find element"
// ErrWaitJSTimeout error code
ErrWaitJSTimeout ErrCode = "wait js timeout"
// ErrSrcNotFound error code
ErrSrcNotFound ErrCode = "element doesn't have src attribute"
// ErrEval error code
ErrEval ErrCode = "eval error"
// ErrNavigation error code
ErrNavigation ErrCode = "navigation failed"
)
// Error ...
type Error struct {
Err error
Code ErrCode
Details interface{}
}
// Error ...
func (e *Error) Error() string {
return fmt.Sprintf("[rod] %s\n%v", e.Code, e.Details)
}
// Unwrap ...
func (e *Error) Unwrap() error {
return e.Err
}
// IsError type matches
func IsError(err error, code ErrCode) bool {
if err == nil {
return false
}
e, ok := err.(*Error)
if !ok {
return false
}
return e.Code == code
}