Skip to content

Commit

Permalink
エラー見れるように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
aikizoku committed Nov 1, 2021
1 parent 35483a4 commit ec70a72
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,17 @@ func PostJSON(ctx context.Context, url string, param interface{}, res interface{

status, body, err := send(ctx, req, opt)
if body != nil && len(body) > 0 {
errRes := map[string]interface{}{}
err = json.Unmarshal(body, &errRes)
if err != nil {
log.Warningm(ctx, "json.Unmarshal", err)
return status, err
if status == http.StatusOK {
perr := json.Unmarshal(body, res)
if perr != nil {
log.Warningm(ctx, "json.Unmarshal", perr)
err = perr
}
} else {
errRes := map[string]interface{}{}
err = json.Unmarshal(body, &errRes)
log.Warningf(ctx, "%v", errRes)
}
log.Warningf(ctx, "%v", errRes)
}
return status, err
}
Expand Down Expand Up @@ -176,14 +180,18 @@ func PutJSON(ctx context.Context, url string, param interface{}, res interface{}
}

status, body, err := send(ctx, req, opt)
if status != http.StatusOK {
return status, err
}

err = json.Unmarshal(body, res)
if err != nil {
log.Warningm(ctx, "json.Unmarshal", err)
return status, err
if body != nil && len(body) > 0 {
if status == http.StatusOK {
perr := json.Unmarshal(body, res)
if perr != nil {
log.Warningm(ctx, "json.Unmarshal", perr)
err = perr
}
} else {
errRes := map[string]interface{}{}
err = json.Unmarshal(body, &errRes)
log.Warningf(ctx, "%v", errRes)
}
}
return status, err
}
Expand Down Expand Up @@ -283,14 +291,18 @@ func DeleteJSON(ctx context.Context, url string, param interface{}, res interfac
}

status, body, err := send(ctx, req, opt)
if status != http.StatusOK {
return status, err
}

err = json.Unmarshal(body, res)
if err != nil {
log.Warningm(ctx, "json.Unmarshal", err)
return status, err
if body != nil && len(body) > 0 {
if status == http.StatusOK {
perr := json.Unmarshal(body, res)
if perr != nil {
log.Warningm(ctx, "json.Unmarshal", perr)
err = perr
}
} else {
errRes := map[string]interface{}{}
err = json.Unmarshal(body, &errRes)
log.Warningf(ctx, "%v", errRes)
}
}
return status, err
}
Expand Down

0 comments on commit ec70a72

Please sign in to comment.