Skip to content

Commit

Permalink
Display validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-hudelmaier committed Sep 8, 2022
1 parent 9037b54 commit 1ba2849
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions services/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package services
import (
"errors"
"fmt"
"io/ioutil"
"net/http"
)

Expand All @@ -19,6 +20,13 @@ func getApiUrl(devMode bool, path string) string {
func handleRestResponse(entityName string, resp *http.Response) error {
if resp.StatusCode == 401 {
return errors.New("you are not logged in, please login using 'checkson login'")
} else if resp.StatusCode == 400 {

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return errors.New("validation error: Cannot read response")
}
return errors.New("validation error: " + string(body[:]))
} else if resp.StatusCode == 200 {
return nil
} else if resp.StatusCode == 404 {
Expand Down

0 comments on commit 1ba2849

Please sign in to comment.