This repository was archived by the owner on Feb 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
69 lines (56 loc) · 1.55 KB
/
errors.go
File metadata and controls
69 lines (56 loc) · 1.55 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
62
63
64
65
66
67
68
69
package ot
import (
"errors"
"fmt"
"regexp"
"github.com/itcomusic/ot/internal/client"
)
var (
regDuplicate = regexp.MustCompile(`^An item with the name '.*' already exists.$`)
ErrTokenExpire = fmt.Errorf("ot: token expired")
)
type NodeRetrievalError struct {
*client.OpError
isNotFound bool
}
func (re *NodeRetrievalError) NotFound() bool {
return re.isNotFound
}
type DuplicateNameError struct {
*client.OpError
}
func errIn(r *client.Response, err error) error {
if err != nil {
return err
}
// -2147482645, -2147482644, -2147482643 login failed
// -2147482642 session expire, when using token may be?
// 903102 not found service
// 903101 custom error
switch r.Status {
case 0:
return nil
case -2147482642:
return ErrTokenExpire
case -2147482645, -2147482644, -2147482643, 903102:
return errors.New("ot: " + r.StatusMessage)
default:
switch r.StatusMessage {
case "DocMan.NodeRetrievalError":
nfound := false
desc, ecode := r.ErrMessage()
switch ecode {
case "662241287":
nfound = true
}
return &NodeRetrievalError{OpError: &client.OpError{Service: r.Service, Err: errors.New(desc)}, isNotFound: nfound}
case "DocMan.DuplicateName":
return &DuplicateNameError{OpError: &client.OpError{Service: r.Service, Err: errors.New(r.Desc)}}
case "DocMan.NodeCreationError": // why is it not a DocMan.Duplicate:(
if regDuplicate.FindStringIndex(r.Desc) != nil {
return &DuplicateNameError{OpError: &client.OpError{Service: r.Service, Err: errors.New(r.Desc)}}
}
}
return errors.New("ot: " + r.Desc)
}
}