Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions backend/plugins/github/api/remote_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ limitations under the License.
package api

import (
"encoding/json"
goerrors "errors"
"fmt"
"io"
"net/http"
"net/url"

Expand Down Expand Up @@ -90,6 +93,10 @@ func listGithubUserOrgs(
if err != nil {
return nil, nil, err
}
if orgsBody.StatusCode != http.StatusOK {
err := errors.Convert(tryToResolveErrorMessage(orgsBody))
return nil, nil, err
}
var orgs []org
if err := api.UnmarshalResponse(orgsBody, &orgs); err != nil {
return nil, nil, err
Expand All @@ -112,6 +119,29 @@ func listGithubUserOrgs(
return children, nextPage, nil
}

func tryToResolveErrorMessage(resp *http.Response) error {
if resp == nil {
return goerrors.New("nil response")
}
type Response struct {
Message string `json:"message"`
DocumentationURL string `json:"documentation_url"`
}
resBody, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
return err
}
if len(resBody) == 0 {
return goerrors.New("empty response")
}
var respStruct Response
if err := json.Unmarshal(resBody, &respStruct); err != nil {
return err
}
return fmt.Errorf("response status code: %d, message: %s", resp.StatusCode, respStruct.Message)
}

func listGithubOrgRepos(
apiClient plugin.ApiClient,
org string,
Expand Down