sms completed

This commit is contained in:
Vladimir V Maksimov
2025-12-03 18:34:25 +03:00
parent d7bd28b759
commit 85cbc3e940
4 changed files with 171 additions and 9 deletions

View File

@@ -9,6 +9,12 @@ import (
"net/url"
)
type ErrorCode struct {
Error int `json:"error"`
Name string `json:"name"`
Message string `json:"message"`
}
func httpRequest(req *http.Request, resp any) error {
client := &http.Client{}
@@ -23,7 +29,13 @@ func httpRequest(req *http.Request, resp any) error {
return fmt.Errorf("http response read error: %w", err)
}
//log.Println(string(body))
if err = json.Unmarshal(body, resp); err != nil {
var rErr ErrorCode
if err = json.Unmarshal(body, &rErr); err == nil && rErr.Error != 0 {
return fmt.Errorf("error %d %s: %s", rErr.Error, rErr.Name, rErr.Message)
}
err = fmt.Errorf("http response unmarshal error: %w", err)
}
return err