Skip to content

Commit

Permalink
Add AuthError type, use it.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Dec 19, 2016
1 parent e259c64 commit b230afe
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
13 changes: 4 additions & 9 deletions remote/bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bitbucket

import (
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions remote/errors.go
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 4 additions & 9 deletions remote/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package github

import (
"crypto/tls"
"errors"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -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
Expand Down
13 changes: 4 additions & 9 deletions remote/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gitlab

import (
"crypto/tls"
"errors"
"fmt"
"io/ioutil"
"net"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b230afe

Please sign in to comment.