-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.go
More file actions
61 lines (50 loc) · 1.62 KB
/
errors.go
File metadata and controls
61 lines (50 loc) · 1.62 KB
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
55
56
57
58
59
60
61
package adspower
import (
"errors"
"fmt"
"strings"
)
type (
ErrProfileLimitExceeded error
ErrProxyFailure error
ErrProfileNotFound error
ErrGroupNotFound error
ErrNoGroupsFound error
ErrOpenBrowserFailure error
ErrCloseBrowserFailure error
ErrInvalIdProxyFormat error
)
var (
errProfileLimitReached ErrProfileLimitExceeded = errors.New("profile limit reached")
errProxyFailure ErrProxyFailure = errors.New("proxy failure")
errInvalIdProxyFormat ErrInvalIdProxyFormat = errors.New("invalId proxy format")
errGroupNotFound ErrGroupNotFound = errors.New("group not found")
errProfileNotFound ErrProfileNotFound = errors.New("profile not found")
errNoGroupsFound ErrNoGroupsFound = errors.New("no groups found")
errOpenBrowserFailure ErrOpenBrowserFailure = errors.New("open browser failure")
errStopBrowserFailure ErrCloseBrowserFailure = errors.New("close browser failure")
ErrUnknownError error
)
func handleResponseError(r iResponseMessage) error {
if r.GetCode() == 0 {
return nil
}
msg := r.GetMsg()
switch {
case strings.Contains(msg, "proxy"):
return errProxyFailure
case strings.Contains(msg, "not open"):
return errStopBrowserFailure
case strings.Contains(msg, "exceeds"):
return errProfileLimitReached
case strings.Contains(msg, "does not exist"):
return errOpenBrowserFailure
case strings.Contains(msg, "wrong user_ids"):
return errProfileNotFound
case strings.Contains(msg, "group id error"):
return errGroupNotFound
default:
ErrUnknownError = fmt.Errorf(msg)
return ErrUnknownError
}
}