-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
48 lines (40 loc) · 742 Bytes
/
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
48
package rest
import (
"errors"
"fmt"
"io/fs"
"os"
)
var ErrLoginRequired = errors.New("login required")
type Error struct {
Response *Response
parent error
}
func (r *Error) Error() string {
return fmt.Sprintf("[rest] error from server: %s", r.Response.Error)
}
func (r *Error) Unwrap() error {
if r.parent != nil {
return r.parent
}
// check for various type of errors
switch r.Response.Code {
case 403:
return os.ErrPermission
case 404:
return fs.ErrNotExist
default:
return nil
}
}
type HttpError struct {
Code int
Body []byte
e error // unwrap error
}
func (e *HttpError) Error() string {
return fmt.Sprintf("HTTP Error %d: %s", e.Code, e.Body)
}
func (e *HttpError) Unwrap() error {
return e.e
}