Return network error when logging in and the network connection fails (#3432)
This commit is contained in:
@@ -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")
|
||||
@@ -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 {
|
||||
@@ -111,6 +112,11 @@ func ErrorWithContext(ctx context.Context, err ...interface{}) *CodedAPIError {
|
||||
errorCode = 401
|
||||
errorMessage = ErrInvalidLogin.Error()
|
||||
}
|
||||
if errors.Is(err1, ErrNetworkError) {
|
||||
detailedMessage = ""
|
||||
errorCode = 503
|
||||
errorMessage = ErrNetworkError.Error()
|
||||
}
|
||||
if strings.Contains(strings.ToLower(err1.Error()), ErrAccessDenied.Error()) {
|
||||
errorCode = 403
|
||||
errorMessage = err1.Error()
|
||||
|
||||
@@ -20,8 +20,11 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
stderrors "errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user