cli(fix): better error handling on non-json api responses (clos… (#3104)

Co-authored-by: Rahul Verma <51950008+rahulverma283@users.noreply.github.com>
Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
This commit is contained in:
Rahul Verma 2019-12-27 16:28:36 +05:30 committed by Shahidh K Muhammed
parent 337403d532
commit c6ab1014af
3 changed files with 16 additions and 15 deletions

View File

@ -186,7 +186,7 @@ func (h *HasuraDB) UnLock() error {
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { if err != nil {
return err return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
} }
// Handle migration version here // Handle migration version here
@ -308,7 +308,7 @@ func (h *HasuraDB) getVersions() (err error) {
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { 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) return horror.Error(h.config.isCMD)
@ -393,7 +393,7 @@ func (h *HasuraDB) Reset() error {
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { 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) return horror.Error(h.config.isCMD)
@ -428,7 +428,7 @@ func (h *HasuraDB) ensureVersionTable() error {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { if err != nil {
h.logger.Debug(err) 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) return horror.Error(h.config.isCMD)
} }
@ -465,7 +465,7 @@ func (h *HasuraDB) ensureVersionTable() error {
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { 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) return horror.Error(h.config.isCMD)

View File

@ -2,6 +2,7 @@ package hasuradb
import ( import (
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"github.com/hasura/graphql-engine/cli/migrate/database" "github.com/hasura/graphql-engine/cli/migrate/database"
@ -28,7 +29,7 @@ func (h *HasuraDB) ExportMetadata() (interface{}, error) {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { if err != nil {
h.logger.Debug(err) 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) return nil, horror.Error(h.config.isCMD)
} }
@ -60,7 +61,7 @@ func (h *HasuraDB) ResetMetadata() error {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { if err != nil {
h.logger.Debug(err) 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) return horror.Error(h.config.isCMD)
} }
@ -86,7 +87,7 @@ func (h *HasuraDB) ReloadMetadata() error {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { if err != nil {
h.logger.Debug(err) 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) return horror.Error(h.config.isCMD)
} }
@ -180,7 +181,7 @@ func (h *HasuraDB) ApplyMetadata(data interface{}) error {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { if err != nil {
h.logger.Debug(err) h.logger.Debug(err)
return err return fmt.Errorf("failed parsing json: %v; response from API: %s", err, string(body))
} }
if horror.Path != "" { if horror.Path != "" {
@ -225,7 +226,7 @@ func (h *HasuraDB) Query(data []interface{}) error {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { if err != nil {
h.logger.Debug(err) 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) return horror.Error(h.config.isCMD)
} }

View File

@ -31,7 +31,7 @@ func (h *HasuraDB) ensureSettingsTable() error {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { if err != nil {
h.logger.Debug(err) 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) return horror.Error(h.config.isCMD)
} }
@ -69,7 +69,7 @@ func (h *HasuraDB) ensureSettingsTable() error {
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { 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) return horror.Error(h.config.isCMD)
@ -115,7 +115,7 @@ func (h *HasuraDB) setDefaultSettings() error {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { if err != nil {
h.logger.Debug(err) 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) return horror.Error(h.config.isCMD)
} }
@ -144,7 +144,7 @@ func (h *HasuraDB) GetSetting(name string) (value string, err error) {
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { 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) return value, horror.Error(h.config.isCMD)
@ -193,7 +193,7 @@ func (h *HasuraDB) UpdateSetting(name string, value string) error {
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
err = json.Unmarshal(body, &horror) err = json.Unmarshal(body, &horror)
if err != nil { 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) return horror.Error(h.config.isCMD)