Skip to content

Commit

Permalink
Return network error when logging in and the network connection fails
Browse files Browse the repository at this point in the history
  • Loading branch information
marktheunissen committed Sep 5, 2024
1 parent 4c432cd commit ab4ea95
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ test-start-docker-minio-w-redirect-url: initialize-docker-network
-e MINIO_SERVER_URL='http://localhost:9000' \
-v /data1 -v /data2 -v /data3 -v /data4 \
-d --network host --name minio --rm\
quay.io/minio/minio:latest server /data{1...4})
quay.io/minio/minio:latest server /data{1...4})

test-start-docker-nginx-w-subpath:
@(docker run \
Expand Down
8 changes: 7 additions & 1 deletion api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

var (
ErrDefault = errors.New("an error occurred, please try again")
ErrInvalidLogin = errors.New("invalid Login")
ErrInvalidLogin = errors.New("invalid login")
ErrForbidden = errors.New("403 Forbidden")
ErrBadRequest = errors.New("400 Bad Request")
ErrFileTooLarge = errors.New("413 File too Large")
Expand Down Expand Up @@ -73,6 +73,7 @@ var (
ErrPolicyNotFound = errors.New("policy does not exist")
ErrLoginNotAllowed = errors.New("login not allowed")
ErrHealthReportFail = errors.New("failure to generate Health report")
ErrNetworkError = errors.New("unable to login due to network error")
)

type CodedAPIError struct {
Expand Down Expand Up @@ -111,6 +112,11 @@ func ErrorWithContext(ctx context.Context, err ...interface{}) *CodedAPIError {
errorCode = 401
errorMessage = ErrInvalidLogin.Error()
}
if errors.Is(err1, ErrNetworkError) {
detailedMessage = ""
errorCode = 401
errorMessage = ErrNetworkError.Error()
}
if strings.Contains(strings.ToLower(err1.Error()), ErrAccessDenied.Error()) {
errorCode = 403
errorMessage = err1.Error()
Expand Down
10 changes: 9 additions & 1 deletion api/user_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import (
"context"
"encoding/base64"
"encoding/json"
stderrors "errors"
"fmt"
"net"
"net/http"
"net/url"
"strings"

"github.com/go-openapi/errors"
Expand Down Expand Up @@ -142,7 +145,6 @@ func getLoginResponse(params authApi.LoginParams) (*models.LoginResponse, *Coded
if credsVerificate.SessionToken == "" || credsVerificate.SecretAccessKey == "" || credsVerificate.AccessKeyID == "" {
return nil, ErrorWithContext(ctx, errors.New(401, "Invalid STS Params"))
}

} else {
clientIP := getClientIP(params.HTTPRequest)
// prepare console credentials
Expand All @@ -158,6 +160,12 @@ func getLoginResponse(params authApi.LoginParams) (*models.LoginResponse, *Coded
}
sessionID, err := login(consoleCreds, sf)
if err != nil {
var urlErr *url.Error
if stderrors.As(err, &urlErr) {
if _, isNetErr := urlErr.Err.(net.Error); isNetErr {
return nil, ErrorWithContext(ctx, ErrNetworkError)
}
}
return nil, ErrorWithContext(ctx, err, ErrInvalidLogin)
}
// serialize output
Expand Down

0 comments on commit ab4ea95

Please sign in to comment.