ошибки

This commit is contained in:
lost+skunk 2024-09-04 20:18:39 +03:00
parent 4487cdcbe9
commit b3c99749f1
5 changed files with 46 additions and 31 deletions

22
util.go
View file

@ -15,11 +15,25 @@ func try(txt error) {
}
}
// сокращение для вызова щенка и парсинга жсона
func ujson(data string, output any) {
func ujson(data string, output any) Error {
input, err := puppy(data)
try(err)
try(json.Unmarshal([]byte(input), output))
if err == nil {
try(json.Unmarshal([]byte(input), output))
}
return APIError(err)
}
type Error struct {
Reason string `json:"error"`
Error string `json:"errorDescription"`
RAW []byte `json:"-"`
}
func APIError(inputError error) (err Error) {
if inputError != nil {
err.RAW = []byte(inputError.Error())
try(json.Unmarshal(err.RAW, &err))
}
return
}
/* REQUEST SECTION */