-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
common/errors: Refactor common error type into pkg/common
Signed-off-by: Yannis Zarkadas <[email protected]>
- Loading branch information
1 parent
b8788fd
commit 8bf6100
Showing
8 changed files
with
47 additions
and
37 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,32 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
// RequestError is an error returned when an HTTP request goes wrong. | ||
// For example, an error status code is returned. | ||
type RequestError struct { | ||
// Response is the HTTP Response struct | ||
Response *http.Response | ||
// Body is the bytes parsed from the Response struct. This must be done | ||
// by the party making the HTTP request. | ||
Body []byte | ||
} | ||
|
||
var _ error = &RequestError{} | ||
|
||
func NewRequestError(resp *http.Response, body []byte) error { | ||
return &RequestError{ | ||
Body: body, | ||
Response: resp, | ||
} | ||
} | ||
|
||
func (e *RequestError) Error() string { | ||
// We don't log the body by default, because it can potentially contain | ||
// security-sensitive information. | ||
return fmt.Sprintf("An HTTP request went wrong. Status Code: %d", | ||
e.Response.StatusCode) | ||
} |
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