Debian Codegraph @

v3/error.go

raw symbols SCIP
1 package grab
2
3 import (
4 "errors"
5 "fmt"
6 "net/http"
7 )
8
9 var (
10 // ErrBadLength indicates that the server response or an existing file does
11 // not match the expected content length.
12 ErrBadLength = errors.New("bad content length")
13
14 // ErrBadChecksum indicates that a downloaded file failed to pass checksum
15 // validation.
16 ErrBadChecksum = errors.New("checksum mismatch")
17
18 // ErrNoFilename indicates that a reasonable filename could not be
19 // automatically determined using the URL or response headers from a server.
20 ErrNoFilename = errors.New("no filename could be determined")
21
22 // ErrNoTimestamp indicates that a timestamp could not be automatically
23 // determined using the response headers from the remote server.
24 ErrNoTimestamp = errors.New("no timestamp could be determined for the remote file")
25
26 // ErrFileExists indicates that the destination path already exists.
27 ErrFileExists = errors.New("file exists")
28 )
29
30 // StatusCodeError indicates that the server response had a status code that
31 // was not in the 200-299 range (after following any redirects).
32 type StatusCodeError int
33
34 func (err StatusCodeError) Error() string {
35 return fmt.Sprintf("server returned %d %s", err, http.StatusText(int(err)))
36 }
37
38 // IsStatusCodeError returns true if the given error is of type StatusCodeError.
39 func IsStatusCodeError(err error) bool {
40 _, ok := err.(StatusCodeError)
41 return ok
42 }