Skip to content

Commit

Permalink
Improve error handling on proxy (#911)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>

Co-authored-by: Lenin Alevski <alevsk.8772@gmail.com>
  • Loading branch information
dvaldivia and Alevsk committed Jul 29, 2021
1 parent 64154ca commit 4f7f81b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions operatorapi/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/sha1"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -145,6 +146,12 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
return
}

if loginResp.StatusCode < 200 && loginResp.StatusCode <= 299 {
log.Println(fmt.Printf("Status: %d. Couldn't complete login", loginResp.StatusCode))
responseWriter.WriteHeader(500)
return
}

for _, c := range loginResp.Cookies() {
if c.Name == "token" {
tenantCookie = c
Expand All @@ -162,6 +169,11 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
}
defer loginResp.Body.Close()
}
if tenantCookie == nil {
log.Println(errors.New("couldn't login to tenant and get cookie"))
responseWriter.WriteHeader(500)
return
}

targetURL, err := url2.Parse(tenantURL)
if err != nil {
Expand Down

0 comments on commit 4f7f81b

Please sign in to comment.