-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Improve HTTP error message response
Dedicated structure to return HTTP error messages. ATM only for DeployService method
- Loading branch information
Showing
2 changed files
with
32 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
type HttpResponseError struct { | ||
Code int | ||
Message string | ||
} | ||
|
||
func toHttpResponseError(response *http.Response) *HttpResponseError { | ||
body, _ := io.ReadAll(response.Body) | ||
response.Body.Close() | ||
return &HttpResponseError{ | ||
Code: response.StatusCode, | ||
Message: string(body), | ||
} | ||
} | ||
|
||
func (m *HttpResponseError) Error() string { | ||
return fmt.Sprintf("\nHTTP Response Code: %d\nError Message: %s", m.Code, m.Message) | ||
} |
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