diff options
| author | lost+skunk <[email protected]> | 2024-09-04 20:18:39 +0300 |
|---|---|---|
| committer | lost+skunk <[email protected]> | 2024-09-04 20:18:39 +0300 |
| commit | b3c99749f133abf6c04506135c2e4e7567da5254 (patch) | |
| tree | 2dd1abd4967eae3d151eff30404ab28ffd7054b1 /util.go | |
| parent | 4487cdcbe9ed2ad4bc661c04600336505054177c (diff) | |
| download | devianter-b3c99749f133abf6c04506135c2e4e7567da5254.tar.gz devianter-b3c99749f133abf6c04506135c2e4e7567da5254.tar.bz2 devianter-b3c99749f133abf6c04506135c2e4e7567da5254.zip | |
ошибки
Diffstat (limited to 'util.go')
| -rw-r--r-- | util.go | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -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 */ |
