-
Notifications
You must be signed in to change notification settings - Fork 4
/
errors.go
51 lines (42 loc) · 1.29 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
package moysklad
import (
"fmt"
)
// ApiError Структура ошибки API МойСклад.
// Документация МойСклад: https://dev.moysklad.ru/doc/api/remap/1.2/#mojsklad-json-api-obschie-swedeniq-obrabotka-oshibok
type ApiError struct {
Meta Meta `json:"meta"`
Message string `json:"error"`
Parameter string `json:"parameter"`
ErrorMessage string `json:"error_message"`
MoreInfo string `json:"moreInfo"`
Dependencies []Meta `json:"dependencies"`
Code int `json:"code"`
Line int `json:"line"`
Column int `json:"column"`
}
func (e ApiError) Error() string {
return fmt.Sprintf("%v %v %v %v", e.Code, e.Message, e.ErrorMessage, e.MoreInfo)
}
type ApiErrors struct {
ApiErrors []ApiError `json:"errors"`
}
func (e ApiErrors) Error() string {
var message string
for _, er := range e.ApiErrors {
message += fmt.Sprintf("%v %v %v %v\n", er.Code, er.Message, er.ErrorMessage, er.MoreInfo)
}
return message
}
type ErrUnknownEntity struct {
t any
}
func (e ErrUnknownEntity) Error() string {
return fmt.Sprintf("unrecognized entity: %v", e.t)
}
type ErrWrongMetaType struct {
have, need MetaType
}
func (e ErrWrongMetaType) Error() string {
return fmt.Sprintf("meta type mismatch! have %s, need %s", e.have, e.need)
}