mirror of
https://github.com/harness/drone.git
synced 2025-05-13 23:50:47 +08:00
Add AuthError type, use it.
This commit is contained in:
parent
e259c64bac
commit
b230afe7f5
@ -1,7 +1,6 @@
|
|||||||
package bitbucket
|
package bitbucket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -46,15 +45,11 @@ func (c *config) Login(w http.ResponseWriter, req *http.Request) (*model.User, e
|
|||||||
|
|
||||||
// get the OAuth errors
|
// get the OAuth errors
|
||||||
if err := req.FormValue("error"); err != "" {
|
if err := req.FormValue("error"); err != "" {
|
||||||
description := req.FormValue("error_description")
|
return nil, &remote.AuthError{
|
||||||
if description != "" {
|
Err: err,
|
||||||
err += " " + description
|
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
|
// 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 (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -95,15 +94,11 @@ func (c *client) Login(res http.ResponseWriter, req *http.Request) (*model.User,
|
|||||||
|
|
||||||
// get the OAuth errors
|
// get the OAuth errors
|
||||||
if err := req.FormValue("error"); err != "" {
|
if err := req.FormValue("error"); err != "" {
|
||||||
description := req.FormValue("error_description")
|
return nil, &remote.AuthError{
|
||||||
if description != "" {
|
Err: err,
|
||||||
err += " " + description
|
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
|
// get the OAuth code
|
||||||
|
@ -2,7 +2,6 @@ package gitlab
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
@ -118,15 +117,11 @@ func (g *Gitlab) Login(res http.ResponseWriter, req *http.Request) (*model.User,
|
|||||||
|
|
||||||
// get the OAuth errors
|
// get the OAuth errors
|
||||||
if err := req.FormValue("error"); err != "" {
|
if err := req.FormValue("error"); err != "" {
|
||||||
description := req.FormValue("error_description")
|
return nil, &remote.AuthError{
|
||||||
if description != "" {
|
Err: err,
|
||||||
err += " " + description
|
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
|
// get the OAuth code
|
||||||
|
Loading…
Reference in New Issue
Block a user