Merge pull request #4087 from cli/graphql-error-fix

Fix unmarshalling GraphQL error type
This commit is contained in:
Mislav Marohnić 2021-08-04 15:43:00 +02:00 committed by GitHub
commit 95a515ecf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 12 deletions

View file

@ -123,8 +123,8 @@ type graphQLResponse struct {
// GraphQLError is a single error returned in a GraphQL response
type GraphQLError struct {
Type string
Path []string
Message string
// Path []interface // mixed strings and numbers
}
// GraphQLErrorResponse contains errors returned in a GraphQL response

View file

@ -130,17 +130,7 @@ func mapRepoNameToID(client *api.Client, host, orgName string, repositoryNames [
DatabaseID int `json:"databaseId"`
})
err := client.GraphQL(host, query, nil, &graphqlResult)
gqlErr, isGqlErr := err.(*api.GraphQLErrorResponse)
if isGqlErr {
for _, ge := range gqlErr.Errors {
if ge.Type == "NOT_FOUND" {
return nil, fmt.Errorf("could not find %s/%s", orgName, ge.Path[0])
}
}
}
if err != nil {
if err := client.GraphQL(host, query, nil, &graphqlResult); err != nil {
return nil, fmt.Errorf("failed to look up repositories: %w", err)
}