-
Notifications
You must be signed in to change notification settings - Fork 2
/
error.go
74 lines (58 loc) · 2.4 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package newsapi
import (
"errors"
"fmt"
)
var (
// ErrInvalidQueryLength is returned whenever query length exceeds
// maximum characters size, which is 500.
ErrInvalidQueryLength = errors.New("query exceeds 500 character limit")
// ErrInvalidSearchIn is returned whenever search in type has a value
// that is not predefined list.
ErrInvalidSearchIn = errors.New("invalid search key")
// ErrInvalidFromTime is returned whenever from and to times are used
// and to is earlier than the from time.
ErrInvalidFromTime = errors.New("from time cannot be after to time")
// ErrInvalidCategory is returned whenever category type has a value
// that is not in the predefined list.
ErrInvalidCategory = errors.New("invalid category")
// ErrInvalidLanguage is returned whenever language type has a value
// that is not in the predefined list.
ErrInvalidLanguage = errors.New("invalid language")
// ErrInvalidCountry is returned whenever country type has a value
// that is not in the predefined list.
ErrInvalidCountry = errors.New("invalid country")
// ErrInvalidSortBy is returned whenever sort by type has a value
// that is not in the predefined list.
ErrInvalidSortBy = errors.New("invalid sort key")
// ErrInvalidPageSize is returned whenever page size exceeds a
// maximum of 100 entries.
ErrInvalidPageSize = errors.New("page size exceeds 100 entries limit")
// ErrIncompatibleParams is returned whenever in TopHeadlinesParams
// parameters sources is used along with country or category.
ErrIncompatibleParams = errors.New("country/category parameter cannot be used along with sources parameter")
// ErrTooManySources is returned whenever sources list exceeds 20
// entries.
ErrTooManySources = errors.New("sources exceeds 20 entries limit")
// ErrParamsScopeTooBroad is returned when the scope of parameters is
// too broad.
ErrParamsScopeTooBroad = errors.New("scope of parameters is too broad")
)
// Error contains newsapi error information.
type Error struct {
// HTTPCode specifies the response status code.
HTTPCode int
// APICode specifies the error code returned from newsapi.
APICode string
// Message specifies the error message returned from newsapi.
Message string
}
// Error implements error interface and returns formatted error message.
func (e *Error) Error() string {
return fmt.Sprintf(
`message: %q (http code: "%d"; api code: %q)`,
e.Message,
e.HTTPCode,
e.APICode,
)
}