-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes NewClient definition and removes bloated interface
Changes NewClient definition and removes bloated interface Signed-off-by: Dmitry Kisler <admin@dkisler.com>
- Loading branch information
Showing
18 changed files
with
622 additions
and
897 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package sdk | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io" | ||
"net/http" | ||
"strconv" | ||
) | ||
|
||
// Error API error. | ||
type Error struct { | ||
HTTPCode int | ||
errorResp | ||
} | ||
|
||
func (e Error) Error() string { | ||
return "[HTTP Code: " + strconv.Itoa(e.HTTPCode) + "][Error Code: " + e.Code + "] " + e.Message | ||
} | ||
|
||
func (e Error) httpResp() *http.Response { | ||
o, _ := json.Marshal(e.errorResp) | ||
return &http.Response{ | ||
Status: e.Code, | ||
StatusCode: e.HTTPCode, | ||
Body: io.NopCloser(bytes.NewReader(o)), | ||
ContentLength: int64(len(o)), | ||
} | ||
} | ||
|
||
type errorResp struct { | ||
Code string `json:"code"` | ||
Message string `json:"message"` | ||
} | ||
|
||
func convertErrorResponse(res *http.Response) error { | ||
var v errorResp | ||
buf, err := io.ReadAll(res.Body) | ||
defer func() { _ = res.Body.Close() }() | ||
if err != nil { | ||
return Error{ | ||
HTTPCode: res.StatusCode, | ||
errorResp: errorResp{ | ||
Message: "cannot read response bytes", | ||
}, | ||
} | ||
} | ||
if err := json.Unmarshal(buf, &v); err != nil { | ||
return Error{ | ||
HTTPCode: res.StatusCode, | ||
errorResp: errorResp{ | ||
Message: err.Error(), | ||
}, | ||
} | ||
} | ||
return Error{ | ||
HTTPCode: res.StatusCode, | ||
errorResp: v, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.