forked from PuerkitoBio/gocrawl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
75 lines (63 loc) · 1.75 KB
/
errors.go
File metadata and controls
75 lines (63 loc) · 1.75 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
package gocrawl
import (
"errors"
)
var (
// The error returned when a redirection is requested, so that the
// worker knows that this is not an actual Fetch error, but a request to
// enqueue the redirect-to URL.
ErrEnqueueRedirect = errors.New("redirection not followed")
// The error returned when the maximum number of visits, as specified by the
// Options field MaxVisits, is reached.
ErrMaxVisits = errors.New("the maximum number of visits is reached")
ErrInterrupted = errors.New("interrupted")
)
// Enum indicating the kind of the crawling error.
type CrawlErrorKind uint8
const (
CekFetch CrawlErrorKind = iota
CekParseRobots
CekHttpStatusCode
CekReadBody
CekParseBody
CekParseURL
CekProcessLinks
CekParseRedirectURL
)
var (
lookupCek = [...]string{
CekFetch: "Fetch",
CekParseRobots: "ParseRobots",
CekHttpStatusCode: "HttpStatusCode",
CekReadBody: "ReadBody",
CekParseBody: "ParseBody",
CekParseURL: "ParseURL",
CekProcessLinks: "ProcessLinks",
CekParseRedirectURL: "ParseRedirectURL",
}
)
func (this CrawlErrorKind) String() string {
return lookupCek[this]
}
// Crawl error information.
type CrawlError struct {
Ctx *URLContext
Err error
Kind CrawlErrorKind
msg string
}
// Implementation of the error interface.
func (this CrawlError) Error() string {
if this.Err != nil {
return this.Err.Error()
}
return this.msg
}
// Create a new CrawlError based on a source error.
func newCrawlError(ctx *URLContext, e error, kind CrawlErrorKind) *CrawlError {
return &CrawlError{ctx, e, kind, ""}
}
// Create a new CrawlError with the specified message.
func newCrawlErrorMessage(ctx *URLContext, msg string, kind CrawlErrorKind) *CrawlError {
return &CrawlError{ctx, nil, kind, msg}
}