-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
78 lines (66 loc) · 2.08 KB
/
Copy patherrors.go
File metadata and controls
78 lines (66 loc) · 2.08 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
70
71
72
73
74
75
76
77
78
package resource
import (
"fmt"
"golang.org/x/xerrors"
)
// xErrorsFrameCaller is passed into error functions to indicate the default stack frame
const xErrorsFrameCaller = 1
// Error is coded error for more granular tracking
type Error struct {
URL string
Message string
Code int
Frame xerrors.Frame
}
// FormatError will print a simple message to the Printer object. This will be what you see when you Println or use %s/%v in a formatted print statement.
func (e Error) FormatError(p xerrors.Printer) error {
if len(e.URL) > 0 {
p.Printf("LECTIORES-%d %s (%s)", e.Code, e.Message, e.URL)
} else {
p.Printf("LECTIORES-%d %s", e.Code, e.Message)
}
e.Frame.Format(p)
return nil
}
// Format provide backwards compatibility with pre-xerrors package
func (e Error) Format(f fmt.State, c rune) {
xerrors.FormatError(e, f, c)
}
// Format provide backwards compatibility with pre-xerrors package
func (e Error) Error() string {
return fmt.Sprint(e)
}
func targetURLIsBlankError(frame xerrors.Frame) *Error {
return &Error{
Message: "TargetURL is blank",
Code: 50,
Frame: frame,
}
}
func targetURLIsNilError(frame xerrors.Frame) *Error {
return &Error{
Message: "TargetURL is Nil",
Code: 51,
Frame: frame,
}
}
// InvalidHTTPRespStatusCodeError is thrown when the HTTP status code is not 200
type InvalidHTTPRespStatusCodeError struct {
URL string
HTTPStatusCode int
Frame xerrors.Frame
}
// FormatError will print a simple message to the Printer object. This will be what you see when you Println or use %s/%v in a formatted print statement.
func (e InvalidHTTPRespStatusCodeError) FormatError(p xerrors.Printer) error {
p.Printf("LECTIORES-200 Expected HTTP Response Status Code 200, got %d (%s)", e.HTTPStatusCode, e.URL)
e.Frame.Format(p)
return nil
}
// Format provide backwards compatibility with pre-xerrors package
func (e InvalidHTTPRespStatusCodeError) Format(f fmt.State, c rune) {
xerrors.FormatError(e, f, c)
}
// Format provide backwards compatibility with pre-xerrors package
func (e InvalidHTTPRespStatusCodeError) Error() string {
return fmt.Sprint(e)
}