aboutsummaryrefslogtreecommitdiff
path: root/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'util.go')
-rw-r--r--util.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/util.go b/util.go
index fb9a73d..7df68cb 100644
--- a/util.go
+++ b/util.go
@@ -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 */