mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-30 10:11:23 +02:00
Add AuthError type, use it.
This commit is contained in:
parent
e259c64bac
commit
b230afe7f5
@ -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
|
||||
|
23
remote/errors.go
Normal file
23
remote/errors.go
Normal file
@ -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)
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user