Skip to content

Commit

Permalink
myshoes-sdk-go return error response
Browse files Browse the repository at this point in the history
  • Loading branch information
whywaita committed Sep 28, 2022
1 parent 2c130d2 commit 3afe697
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions api/myshoes/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package myshoes
import (
"encoding/json"
"fmt"
"io"
"net/http"

"github.com/whywaita/myshoes/pkg/web"
Expand All @@ -11,8 +12,15 @@ import (
func decodeBody(resp *http.Response, out interface{}) error {
defer resp.Body.Close()

decoder := json.NewDecoder(resp.Body)
return decoder.Decode(out)
body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to io.ReadAll(resp.Body): %w", err)
}

if err := json.Unmarshal(body, out); err != nil {
return fmt.Errorf("failed to json.Unmarshal() (out: %s): %w", body, err)
}
return nil
}

func decodeErrorBody(resp *http.Response) error {
Expand Down
1 change: 1 addition & 0 deletions pkg/runner/runner_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (m *Manager) removeRunners(ctx context.Context, t datastore.Target) error {

func (m *Manager) removeRunner(ctx context.Context, t datastore.Target, runner datastore.Runner, ghRunners []*github.Runner) error {
if err := sanitizeRunnerMustRunningTime(runner); errors.Is(err, ErrNotWillDeleteRunner) {
logger.Logf(false, "%s is not running MustRunningTime", runner.UUID)
return nil
}

Expand Down

0 comments on commit 3afe697

Please sign in to comment.