Skip to content

Commit

Permalink
cli(fix): better error handling on non-json api responses (clos… (has…
Browse files Browse the repository at this point in the history
…ura#3104)

Co-authored-by: Rahul Verma <51950008+rahulverma283@users.noreply.github.com>
Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
  • Loading branch information
3 people authored and polRk committed Feb 12, 2020
1 parent d899dbe commit 6ffef86
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
10 changes: 5 additions & 5 deletions cli/migrate/database/hasuradb/hasuradb.go
Expand Up @@ -186,7 +186,7 @@ func (h *HasuraDB) UnLock() error {
if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror)
if err != nil {
return err
return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}

// Handle migration version here
Expand Down Expand Up @@ -308,7 +308,7 @@ func (h *HasuraDB) getVersions() (err error) {
if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror)
if err != nil {
return err
return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}

return horror.Error(h.config.isCMD)
Expand Down Expand Up @@ -393,7 +393,7 @@ func (h *HasuraDB) Reset() error {
if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror)
if err != nil {
return err
return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}

return horror.Error(h.config.isCMD)
Expand Down Expand Up @@ -428,7 +428,7 @@ func (h *HasuraDB) ensureVersionTable() error {
err = json.Unmarshal(body, &horror)
if err != nil {
h.logger.Debug(err)
return err
return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}
return horror.Error(h.config.isCMD)
}
Expand Down Expand Up @@ -465,7 +465,7 @@ func (h *HasuraDB) ensureVersionTable() error {
if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror)
if err != nil {
return err
return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}

return horror.Error(h.config.isCMD)
Expand Down
11 changes: 6 additions & 5 deletions cli/migrate/database/hasuradb/metadata.go
Expand Up @@ -2,6 +2,7 @@ package hasuradb

import (
"encoding/json"
"fmt"
"net/http"

"github.com/hasura/graphql-engine/cli/migrate/database"
Expand All @@ -28,7 +29,7 @@ func (h *HasuraDB) ExportMetadata() (interface{}, error) {
err = json.Unmarshal(body, &horror)
if err != nil {
h.logger.Debug(err)
return nil, err
return nil, fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}
return nil, horror.Error(h.config.isCMD)
}
Expand Down Expand Up @@ -60,7 +61,7 @@ func (h *HasuraDB) ResetMetadata() error {
err = json.Unmarshal(body, &horror)
if err != nil {
h.logger.Debug(err)
return err
return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}
return horror.Error(h.config.isCMD)
}
Expand All @@ -86,7 +87,7 @@ func (h *HasuraDB) ReloadMetadata() error {
err = json.Unmarshal(body, &horror)
if err != nil {
h.logger.Debug(err)
return err
return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}
return horror.Error(h.config.isCMD)
}
Expand Down Expand Up @@ -180,7 +181,7 @@ func (h *HasuraDB) ApplyMetadata(data interface{}) error {
err = json.Unmarshal(body, &horror)
if err != nil {
h.logger.Debug(err)
return err
return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}

if horror.Path != "" {
Expand Down Expand Up @@ -225,7 +226,7 @@ func (h *HasuraDB) Query(data []interface{}) error {
err = json.Unmarshal(body, &horror)
if err != nil {
h.logger.Debug(err)
return err
return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}
return horror.Error(h.config.isCMD)
}
Expand Down
10 changes: 5 additions & 5 deletions cli/migrate/database/hasuradb/settings.go
Expand Up @@ -31,7 +31,7 @@ func (h *HasuraDB) ensureSettingsTable() error {
err = json.Unmarshal(body, &horror)
if err != nil {
h.logger.Debug(err)
return err
return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}
return horror.Error(h.config.isCMD)
}
Expand Down Expand Up @@ -69,7 +69,7 @@ func (h *HasuraDB) ensureSettingsTable() error {
if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror)
if err != nil {
return err
return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}

return horror.Error(h.config.isCMD)
Expand Down Expand Up @@ -115,7 +115,7 @@ func (h *HasuraDB) setDefaultSettings() error {
err = json.Unmarshal(body, &horror)
if err != nil {
h.logger.Debug(err)
return err
return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}
return horror.Error(h.config.isCMD)
}
Expand Down Expand Up @@ -144,7 +144,7 @@ func (h *HasuraDB) GetSetting(name string) (value string, err error) {
if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror)
if err != nil {
return value, err
return value, fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}

return value, horror.Error(h.config.isCMD)
Expand Down Expand Up @@ -193,7 +193,7 @@ func (h *HasuraDB) UpdateSetting(name string, value string) error {
if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror)
if err != nil {
return err
return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
}

return horror.Error(h.config.isCMD)
Expand Down

0 comments on commit 6ffef86

Please sign in to comment.