-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoop-errors.go
More file actions
65 lines (58 loc) · 2.32 KB
/
Copy pathgoop-errors.go
File metadata and controls
65 lines (58 loc) · 2.32 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
package goop
// ErrorType defines types of errors that are possible from goop
type ErrorType int
const (
// ErrUnableToParse will be returned when the HTML could not be parsed
ErrUnableToParse ErrorType = iota
// ErrElementNotFound will be returned when element was not found
ErrElementNotFound
// ErrNoNextSibling will be returned when no next sibling can be found
ErrNoNextSibling
// ErrNoPreviousSibling will be returned when no previous sibling can be found
ErrNoPreviousSibling
// ErrNoNextElementSibling will be returned when no next element sibling can be found
ErrNoNextElementSibling
// ErrNoPreviousElementSibling will be returned when no previous element sibling can be found
ErrNoPreviousElementSibling
// ErrCreatingGetRequest will be returned when the get request couldn't be created
ErrCreatingGetRequest
// ErrInGetRequest will be returned when there was an error during the get request
ErrInGetRequest
// ErrCreatingPostRequest will be returned when the post request couldn't be created
ErrCreatingPostRequest
// ErrMarshallingPostRequest will be returned when the body of a post request couldn't be serialized
ErrMarshallingPostRequest
// ErrReadingResponse will be returned if there was an error reading the response to our get request
ErrReadingResponse
// ErrTimeout will be returned when a request times out
ErrTimeout
)
// Error allows easier introspection on the type of error returned.
// If you know you have a Error, you can compare the Type to one of the exported types
// from this package to see what kind of error it is, then further inspect the Error() method
// to see if it has more specific details for you, like in the case of a ErrElementNotFound
// type of error.
type Error struct {
Type ErrorType
msg string
}
func (se Error) Error() string {
return se.msg
}
func newError(t ErrorType, msg string) Error {
return Error{Type: t, msg: msg}
}
var debug = false
// SetDebug sets the debug status
// Setting this to true causes the panics to be thrown and logged onto the console.
// Setting this to false causes the errors to be saved in the Error field in the returned struct.
// DEPRECATED: Use SetDebugLevel instead for more granular control
func SetDebug(d bool) {
debug = d
// Update debug level for backward compatibility
if d {
debugLevel = DebugBasic
} else {
debugLevel = DebugOff
}
}