Skip to content

Commit

Permalink
Improve CheckResponse message
Browse files Browse the repository at this point in the history
Signed-off-by: arekkas <aeneas@ory.am>
  • Loading branch information
arekkas committed Oct 8, 2018
1 parent 17412ea commit 53a20c8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmdx/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmdx
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
)
Expand All @@ -20,7 +21,17 @@ func CheckResponse(err error, expectedStatusCode int, response *http.Response) {
Must(err, "Command failed because error \"%s\" occurred.\n", err)

if response.StatusCode != expectedStatusCode {
Fatalf("Command failed because status code %d was expected but code %d was received.\n", expectedStatusCode, response.StatusCode)
out, _ := ioutil.ReadAll(response.Body)
Fatalf(
`Command failed because status code %d was expected but code %d was received.
Response payload:
%s`,
expectedStatusCode,
response.StatusCode,
FormatResponse(json.RawMessage(out)),
)
}
}

Expand Down

0 comments on commit 53a20c8

Please sign in to comment.