Skip to content

Commit

Permalink
fix: APIハンドラのエラーハンドリングを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
KinjiKawaguchi committed Mar 24, 2024
1 parent e88b7ec commit 6638bdd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion typing-server/api/handler/score.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ func GetScoresRanking(w http.ResponseWriter, r *http.Request) {
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(rankings)
err = json.NewEncoder(w).Encode(rankings)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}

func PostScore(w http.ResponseWriter, r *http.Request) {
Expand Down
6 changes: 5 additions & 1 deletion typing-server/api/handler/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ func GetUsers(w http.ResponseWriter, r *http.Request) {
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(user)
err = json.NewEncoder(w).Encode(user)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}

0 comments on commit 6638bdd

Please sign in to comment.