From b3c99749f133abf6c04506135c2e4e7567da5254 Mon Sep 17 00:00:00 2001 From: lost+skunk Date: Wed, 4 Sep 2024 20:18:39 +0300 Subject: ошибки MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'util.go') 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 */ -- cgit v1.2.3