Skip to content

Commit

Permalink
fix: not worked error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Nedim Akar authored and Nedim Akar committed Oct 18, 2023
1 parent 55c1b33 commit 7ebe0bf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
15 changes: 11 additions & 4 deletions src/jetstream/errorz/errorz.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ package errorz

import "errors"

var ErrDialTcp = errors.New("dial tcp")
var ErrNoSuchTable = errors.New("no such table")
var ErrNoDatabaseVersionsFound = errors.New("no database versions found")
var Err509Certificate = errors.New("x509: certificate")
const (
ERR_DIAL_TCP = "dial"
ERR_NO_DATABASE_VERSIONS_FOUND = "no database versions found"
ERR_NO_SUCH_TABLE = "no such table"
ERR_X509_CERTIFICATE = "x509: certificate"
)

var ErrDialTcp = errors.New(ERR_DIAL_TCP)
var ErrNoDatabaseVersionsFound = errors.New(ERR_NO_DATABASE_VERSIONS_FOUND)
var ErrNoSuchTable = errors.New(ERR_NO_SUCH_TABLE)
var Err509Certificate = errors.New(ERR_X509_CERTIFICATE)
16 changes: 10 additions & 6 deletions src/jetstream/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"net"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -41,12 +42,15 @@ const APIKeyAuthScheme = "Bearer"
func handleSessionError(config api.PortalConfig, c echo.Context, err error, doNotLog bool, msg string) error {
log.Debug("handleSessionError")

if errors.Is(err, errorz.ErrDialTcp) {
return api.NewHTTPShadowError(
http.StatusServiceUnavailable,
"Service is currently unavailable",
"Service is currently unavailable: %v", err,
)
var netOpErr *net.OpError
if errors.As(err, &netOpErr) {
if netOpErr.Op == errorz.ERR_DIAL_TCP {
return api.NewHTTPShadowError(
http.StatusServiceUnavailable,
"Service is currently unavailable",
"Service is currently unavailable: %v", err,
)
}
}

if doNotLog {
Expand Down
6 changes: 3 additions & 3 deletions src/jetstream/plugins/kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"net/http"
"net/url"
"strconv"
"strings"

"errors"

"github.com/cloudfoundry-incubator/stratos/src/jetstream/errorz"

"github.com/cloudfoundry-incubator/stratos/src/jetstream/api"
"github.com/cloudfoundry-incubator/stratos/src/jetstream/errorz"
"github.com/labstack/echo/v4"
log "github.com/sirupsen/logrus"

Expand Down Expand Up @@ -289,7 +289,7 @@ func (c *KubernetesSpecification) RequiresCert(ec echo.Context) error {
Message string
}
if err != nil {
if errors.Is(err, errorz.Err509Certificate) {
if strings.Contains(err.Error(), errorz.ERR_X509_CERTIFICATE) {
response.Status = http.StatusOK
response.Required = true
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/jetstream/setup_console.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"net/url"
"regexp"
"strconv"

"github.com/cloudfoundry-incubator/stratos/src/jetstream/errorz"
"strings"

"github.com/govau/cf-common/env"
"github.com/labstack/echo/v4"
Expand All @@ -18,6 +17,7 @@ import (
"github.com/cloudfoundry-incubator/stratos/src/jetstream/api"
"github.com/cloudfoundry-incubator/stratos/src/jetstream/api/config"
"github.com/cloudfoundry-incubator/stratos/src/jetstream/crypto"
"github.com/cloudfoundry-incubator/stratos/src/jetstream/errorz"
"github.com/cloudfoundry-incubator/stratos/src/jetstream/repository/console_config"
"github.com/cloudfoundry-incubator/stratos/src/jetstream/repository/localusers"
)
Expand Down Expand Up @@ -94,7 +94,7 @@ func (p *portalProxy) setupGetAvailableScopes(c echo.Context) error {
errInfo, ok := err.(api.ErrHTTPRequest)
if ok {
if errInfo.Status == 0 {
if errors.Is(errInfo, errorz.Err509Certificate) {
if strings.Contains(errInfo.Error(), errorz.ERR_X509_CERTIFICATE) {
return api.NewHTTPShadowError(
http.StatusBadRequest,
"Could not connect to the UAA - Certificate error - check Skip SSL validation setting",
Expand Down

0 comments on commit 7ebe0bf

Please sign in to comment.