diff --git a/remote/bitbucket/bitbucket.go b/remote/bitbucket/bitbucket.go index a03f8ab71..a272fa884 100644 --- a/remote/bitbucket/bitbucket.go +++ b/remote/bitbucket/bitbucket.go @@ -1,7 +1,6 @@ package bitbucket import ( - "errors" "fmt" "net/http" "net/url" @@ -46,15 +45,11 @@ func (c *config) Login(w http.ResponseWriter, req *http.Request) (*model.User, e // get the OAuth errors if err := req.FormValue("error"); err != "" { - description := req.FormValue("error_description") - if description != "" { - err += " " + description + return nil, &remote.AuthError{ + Err: err, + Description: req.FormValue("error_description"), + URI: req.FormValue("error_uri"), } - uri := req.FormValue("error_uri") - if uri != "" { - err += " " + uri - } - return nil, errors.New(err) } // get the OAuth code diff --git a/remote/errors.go b/remote/errors.go new file mode 100644 index 000000000..0ad31e769 --- /dev/null +++ b/remote/errors.go @@ -0,0 +1,23 @@ +package remote + +// AuthError represents remote authentication error. +type AuthError struct { + Err string + Description string + URI string +} + +// Error implements error interface. +func (ae *AuthError) Error() string { + err := ae.Err + if ae.Description != "" { + err += " " + ae.Description + } + if ae.URI != "" { + err += " " + ae.URI + } + return err +} + +// check interface +var _ error = new(AuthError) diff --git a/remote/github/github.go b/remote/github/github.go index fec783703..7b38278b1 100644 --- a/remote/github/github.go +++ b/remote/github/github.go @@ -2,7 +2,6 @@ package github import ( "crypto/tls" - "errors" "fmt" "net" "net/http" @@ -95,15 +94,11 @@ func (c *client) Login(res http.ResponseWriter, req *http.Request) (*model.User, // get the OAuth errors if err := req.FormValue("error"); err != "" { - description := req.FormValue("error_description") - if description != "" { - err += " " + description + return nil, &remote.AuthError{ + Err: err, + Description: req.FormValue("error_description"), + URI: req.FormValue("error_uri"), } - uri := req.FormValue("error_uri") - if uri != "" { - err += " " + uri - } - return nil, errors.New(err) } // get the OAuth code diff --git a/remote/gitlab/gitlab.go b/remote/gitlab/gitlab.go index c41993ef2..5c0192023 100644 --- a/remote/gitlab/gitlab.go +++ b/remote/gitlab/gitlab.go @@ -2,7 +2,6 @@ package gitlab import ( "crypto/tls" - "errors" "fmt" "io/ioutil" "net" @@ -118,15 +117,11 @@ func (g *Gitlab) Login(res http.ResponseWriter, req *http.Request) (*model.User, // get the OAuth errors if err := req.FormValue("error"); err != "" { - description := req.FormValue("error_description") - if description != "" { - err += " " + description + return nil, &remote.AuthError{ + Err: err, + Description: req.FormValue("error_description"), + URI: req.FormValue("error_uri"), } - uri := req.FormValue("error_uri") - if uri != "" { - err += " " + uri - } - return nil, errors.New(err) } // get the OAuth code