diff --git a/errof/errof.go b/errof/errof.go new file mode 100644 index 00000000..afe066b6 --- /dev/null +++ b/errof/errof.go @@ -0,0 +1,27 @@ +package errof + +// ErrorCode is vuls error code +type ErrorCode string + +// Error is vuls error +type Error struct { + Code ErrorCode + Message string +} + +func (e Error) Error() string { + return e.Message +} + +var ( + // ErrFailedToAccessGithubAPI is error of github alert's api access + ErrFailedToAccessGithubAPI ErrorCode = "ErrFailedToAccessGithubAPI" +) + +// New : +func New(code ErrorCode, msg string) Error { + return Error{ + Code: code, + Message: msg, + } +} diff --git a/github/github.go b/github/github.go index dee5bd9b..65d3da67 100644 --- a/github/github.go +++ b/github/github.go @@ -26,11 +26,11 @@ import ( "time" "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/errof" "github.com/future-architect/vuls/models" "github.com/future-architect/vuls/util" "github.com/k0kubun/pp" "golang.org/x/oauth2" - "golang.org/x/xerrors" ) // FillGitHubSecurityAlerts access to owner/repo on GitHub and fetch scurity alerts of the repository via GitHub API v4 GraphQL and then set to the given ScanResult. @@ -75,7 +75,10 @@ func FillGitHubSecurityAlerts(r *models.ScanResult, owner, repo, token string) ( util.Log.Debugf("%s", pp.Sprint(alerts)) if alerts.Data.Repository.URL == "" { - return 0, xerrors.Errorf("Failed to access to GitHub API. Response: %#v", alerts) + return 0, errof.New( + errof.ErrFailedToAccessGithubAPI, + fmt.Sprintf("Failed to access to GitHub API. Response: %#v", alerts), + ) } for _, v := range alerts.Data.Repository.VulnerabilityAlerts.Edges {