-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
57 lines (48 loc) · 1.17 KB
/
errors.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
49
50
51
52
53
54
55
56
57
package valuefirst
import (
"encoding/json"
"fmt"
"github.com/pkg/errors"
"io"
"net/http"
)
// List of errors in the valuefirst package.
var (
ErrEmptyUsername = errors.New("empty username")
ErrEmptyPassword = errors.New("empty password")
ErrDecodeVarIsNotPtr = errors.New("the decode variable is not a pointer")
ErrNilRequest = errors.New("nil request")
)
func formatUnknown(resp *http.Response) (err error) {
b, err := io.ReadAll(resp.Body)
if err != nil {
return
}
err = &UnknownError{
Message: string(b),
}
return
}
// UnknownError is an error that is not defined by the documentation from the ValueFirst.
type UnknownError struct {
Message interface{} `json:"message"`
}
// Error implements the error interface.
func (e UnknownError) Error() string {
return fmt.Sprintf(
"unknown error ValueFirst: message: %v",
e.Message,
)
}
// ErrorList is a list of errors.
type ErrorList []error
// Error implements the error interface.
func (e ErrorList) Error() (res string) {
byteSlice, _ := json.Marshal(e)
res = string(byteSlice)
return
}
// Append appends error to the ErrorList.
func (e *ErrorList) Append(err error) {
*e = append(*e, err)
}