Commit 18556600 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Add more error handling when doing rest calls

parent e8df6b87
......@@ -60,6 +60,19 @@ func restCall(method string, path string, body io.Reader) (responseBytes []byte,
return
}
if response.StatusCode >= 400 {
switch response.StatusCode {
case 403:
err = fmt.Errorf(
"Response: %s\n\tIs your access token valid?\n\tIs the issuer correct?",
response.Status,
)
default:
err = fmt.Errorf("Response: %s", response.Status)
}
return
}
responseBytes, err = ioutil.ReadAll(response.Body)
if err != nil {
return
......@@ -218,9 +231,9 @@ func sshConnect(creds api.Credentials) {
// use the credentials to access the service
if credsBytes, err := json.MarshalIndent(creds, "", " "); err == nil {
log.Printf("Received credentials: %s", credsBytes)
log.Printf("Received credentials:\n%s", credsBytes)
} else {
log.Printf("Received credentials: %s", creds)
log.Printf("Received credentials:\n%s", creds)
}
var (
userOk, hostOk bool
......@@ -252,7 +265,10 @@ func sshConnect(creds api.Credentials) {
cmd.Stdout = os.Stdout
err = cmd.Run()
} else {
fmt.Printf("Deployment successful. You can now ssh to the service using:\nssh -i %s %s@%s'", *pubKey, sshUser, sshHost)
fmt.Printf(
"\nDeployment successful. You can now ssh to the service using:\n ssh -i %s %s@%s'\n",
*pubKey, sshUser, sshHost,
)
}
}
......@@ -266,6 +282,9 @@ func main() {
os.Exit(1)
}
log.Printf("Using issuer: %s", *issuerURI)
log.Printf("Using access token: %s", *accessToken)
var serviceID = findServiceID()
uploadPubKey()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment