diff --git a/client/client.go b/client/client.go index dae88bd..ad19101 100644 --- a/client/client.go +++ b/client/client.go @@ -70,6 +70,11 @@ func (c *RemoteServer) doAction(action string, req []byte) ([]byte, error) { } resp.Body.Close() + // Return response body as error if status code != 200 + if resp.StatusCode != http.StatusOK { + return nil, errors.New(string(body)) + } + return body, nil } diff --git a/cmd/ro/main.go b/cmd/ro/main.go index a40439d..98ed5da 100644 --- a/cmd/ro/main.go +++ b/cmd/ro/main.go @@ -133,6 +133,10 @@ func runEncrypt() { resp, err := roServer.Encrypt(req) processError(err) + if resp.Status != "ok" { + log.Fatal("response status error:", resp.Status) + return + } fmt.Println("Response Status:", resp.Status) outBytes := []byte(base64.StdEncoding.EncodeToString(resp.Response)) ioutil.WriteFile(outPath, outBytes, 0644) @@ -161,6 +165,10 @@ func runReEncrypt() { resp, err := roServer.ReEncrypt(req) processError(err) + if resp.Status != "ok" { + log.Fatal("response status error:", resp.Status) + return + } fmt.Println("Response Status:", resp.Status) outBytes := []byte(base64.StdEncoding.EncodeToString(resp.Response)) ioutil.WriteFile(outPath, outBytes, 0644) @@ -185,10 +193,14 @@ func runDecrypt() { resp, err := roServer.Decrypt(req) processError(err) + if resp.Status != "ok" { + log.Fatal("response status error:", resp.Status) + return + } + fmt.Println("Response Status:", resp.Status) var msg core.DecryptWithDelegates err = json.Unmarshal(resp.Response, &msg) processError(err) - fmt.Println("Response Status:", resp.Status) fmt.Println("Secure:", msg.Secure) fmt.Println("Delegates:", msg.Delegates) ioutil.WriteFile(outPath, msg.Data, 0644)