Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/pkg/gowebdav/errors.go
1560 views
1
package gowebdav
2
3
import (
4
"fmt"
5
"os"
6
)
7
8
// StatusError implements error and wraps
9
// an erroneous status code.
10
type StatusError struct {
11
Status int
12
}
13
14
func (se StatusError) Error() string {
15
return fmt.Sprintf("%d", se.Status)
16
}
17
18
// IsErrCode returns true if the given error
19
// is an os.PathError wrapping a StatusError
20
// with the given status code.
21
func IsErrCode(err error, code int) bool {
22
if pe, ok := err.(*os.PathError); ok {
23
se, ok := pe.Err.(StatusError)
24
return ok && se.Status == code
25
}
26
return false
27
}
28
29
// IsErrNotFound is shorthand for IsErrCode
30
// for status 404.
31
func IsErrNotFound(err error) bool {
32
return IsErrCode(err, 404)
33
}
34
35
func newPathError(op string, path string, statusCode int) error {
36
return &os.PathError{
37
Op: op,
38
Path: path,
39
Err: StatusError{statusCode},
40
}
41
}
42
43
func newPathErrorErr(op string, path string, err error) error {
44
return &os.PathError{
45
Op: op,
46
Path: path,
47
Err: err,
48
}
49
}
50
51