Skip to content

Commit

Permalink
Merge pull request #63 from sapawarga/bugfix-response-json
Browse files Browse the repository at this point in the history
bugfix status code for created, updated and deleted
  • Loading branch information
setiadijoe authored Jul 1, 2021
2 parents f57049d + 99ba897 commit 5a00671
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions transport/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,17 @@ func encodeResponse(ctx context.Context, w http.ResponseWriter, response interfa
return nil
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)

status, ok := response.(*endpoint.StatusResponse)
if ok && status.Code != helper.STATUS_OK {
if ok {
if status.Code == helper.STATUS_CREATED {
w.WriteHeader(http.StatusCreated)
} else if status.Code == helper.STATUS_UPDATED || status.Code == helper.STATUS_DELETED {
w.WriteHeader(http.StatusNoContent)
_ = json.NewEncoder(w).Encode(nil)
return nil
} else {
w.WriteHeader(http.StatusOK)
}
}

Expand Down

0 comments on commit 5a00671

Please sign in to comment.