Skip to content

Commit

Permalink
delete http error
Browse files Browse the repository at this point in the history
  • Loading branch information
Azuki-bar committed Nov 10, 2022
1 parent 2e4e512 commit 2920ea3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions backend/json2grpc/pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package proxy

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

Expand Down Expand Up @@ -54,14 +53,20 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
res, err := h.grpcClient.SendStatus(r.Context(), req)
if err != nil {
log.Println(err)
http.Error(w, fmt.Sprintf(`{"status":"%s"}`, err), http.StatusInternalServerError)
if err := json.NewEncoder(w).Encode(StatusResponse{Status: "err", InternalError: err}); err != nil {
log.Print(err)
}
w.WriteHeader(http.StatusInternalServerError)
return
}
if err := json.NewEncoder(w).Encode(StatusResponse{Status: res.GetResponse().String()}); err != nil {
log.Println(err)
}
w.WriteHeader(http.StatusOK)
default:
http.Error(w, `{"status":"permits only POST"}`, http.StatusMethodNotAllowed)
if err := json.NewEncoder(w).Encode(StatusResponse{Status: "permits only POST"}); err != nil {
log.Print(err)
}
w.WriteHeader(http.StatusMethodNotAllowed)
}
}

0 comments on commit 2920ea3

Please sign in to comment.