-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(relay-proxy): Add log when Github API in error (#1919)
* feat(relay-proxy): Add log when Github API in error Signed-off-by: Thomas Poignant <[email protected]> * early return Signed-off-by: Thomas Poignant <[email protected]> --------- Signed-off-by: Thomas Poignant <[email protected]>
- Loading branch information
1 parent
3d2a2ce
commit aa3696a
Showing
5 changed files
with
113 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package shared | ||
|
||
import ( | ||
"errors" | ||
"github.com/thomaspoignant/go-feature-flag/internal" | ||
"golang.org/x/net/context" | ||
"net/http" | ||
"strings" | ||
"time" | ||
) | ||
|
||
func CallHTTPAPI( | ||
ctx context.Context, | ||
url string, method string, | ||
body string, | ||
timeout time.Duration, | ||
header http.Header, | ||
httpClient internal.HTTPClient) (*http.Response, error) { | ||
if timeout <= 0 { | ||
timeout = 10 * time.Second | ||
} | ||
|
||
if url == "" { | ||
return nil, errors.New("URL is a mandatory parameter when using httpretriever.Retriever") | ||
} | ||
|
||
if method == "" { | ||
method = http.MethodGet | ||
} | ||
|
||
if ctx == nil { | ||
ctx = context.Background() | ||
} | ||
|
||
req, err := http.NewRequestWithContext(ctx, method, url, strings.NewReader(body)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Add header if some are passed | ||
if len(header) > 0 { | ||
req.Header = header | ||
} | ||
|
||
if httpClient == nil { | ||
httpClient = internal.HTTPClientWithTimeout(timeout) | ||
} | ||
|
||
// API call | ||
return httpClient.Do(req) | ||
} |
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