-
-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix stash scraper errors and add apikey field (#5474)
* Use hasura/go-graphql-client instead of shurcooL version * Fix graphql query errors * Support setting api key for stash server
- Loading branch information
1 parent
64fed35
commit 5f690d9
Showing
9 changed files
with
195 additions
and
34 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
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,55 @@ | ||
package scraper | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
|
||
"github.com/hasura/go-graphql-client" | ||
) | ||
|
||
type graphqlErrors []error | ||
|
||
func (e graphqlErrors) Error() string { | ||
b := strings.Builder{} | ||
for _, err := range e { | ||
_, _ = b.WriteString(err.Error()) | ||
} | ||
return b.String() | ||
} | ||
|
||
type graphqlError struct { | ||
err graphql.Error | ||
} | ||
|
||
func (e graphqlError) Error() string { | ||
unwrapped := e.err.Unwrap() | ||
if unwrapped != nil { | ||
var networkErr graphql.NetworkError | ||
if errors.As(unwrapped, &networkErr) { | ||
if networkErr.StatusCode() == 422 { | ||
return networkErr.Body() | ||
} | ||
} | ||
} | ||
return e.err.Error() | ||
} | ||
|
||
// convertGraphqlError converts a graphql.Error or graphql.Errors into an error with a useful message. | ||
// graphql.Error swallows important information, so we need to convert it to a more useful error type. | ||
func convertGraphqlError(err error) error { | ||
var gqlErrs graphql.Errors | ||
if errors.As(err, &gqlErrs) { | ||
ret := make(graphqlErrors, len(gqlErrs)) | ||
for i, e := range gqlErrs { | ||
ret[i] = convertGraphqlError(e) | ||
} | ||
return ret | ||
} | ||
|
||
var gqlErr graphql.Error | ||
if errors.As(err, &gqlErr) { | ||
return graphqlError{gqlErr} | ||
} | ||
|
||
return err | ||
} |
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
Oops, something went wrong.