forked from deankarn/go-download
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
47 lines (38 loc) · 1.21 KB
/
error.go
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
package download
import (
"errors"
"fmt"
)
var (
ErrMaximumSizeExceeded = errors.New("Maximum size exceeded")
ErrInvalidContentLength = errors.New(`Invalid content length`)
ErrBadFileDescriptor = errors.New("bad file descriptor")
_ error = (*InvalidResponseCode)(nil)
_ error = (*DeadlineExceeded)(nil)
_ error = (*Canceled)(nil)
)
// InvalidResponseCode is the error containing the invalid response code error information
type InvalidResponseCode struct {
expected int
got int
}
// Error returns the InvalidResponseCode error string
func (e *InvalidResponseCode) Error() string {
return fmt.Sprintf("Invalid response code, received '%d' expected '%d'", e.got, e.expected)
}
// DeadlineExceeded is the error containing the deadline exceeded error information
type DeadlineExceeded struct {
url string
}
// Error returns the DeadlineExceeded error string
func (e *DeadlineExceeded) Error() string {
return fmt.Sprintf("Download timeout exceeded for '%s'", e.url)
}
// Canceled is the error containing the cancelled error information
type Canceled struct {
url string
}
// Error returns the Canceled error string
func (e *Canceled) Error() string {
return fmt.Sprintf("Download canceled for '%s'", e.url)
}