Improve error handling on proxy (#911)
Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> Co-authored-by: Lenin Alevski <alevsk.8772@gmail.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"crypto/sha1"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@@ -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
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user