Add AuthError type, use it.

This commit is contained in:
Alexey Palazhchenko 2016-12-19 19:22:11 +03:00
parent e259c64bac
commit b230afe7f5
4 changed files with 35 additions and 27 deletions

View file

@ -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
View 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)

View file

@ -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

View file

@ -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