Skip to content

Commit

Permalink
fix: status codes and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mati007thm committed Jan 19, 2024
1 parent e3bbfd1 commit 4074ee2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dapr-distributed-calendar/go/go_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func addEvent(w http.ResponseWriter, r *http.Request) {
if string(bodyBytes) != "" {
log.Printf("Event with ID %s already exists", id)
w.Header().Set("Content-Type", "application/json")
w.Write([]byte("Event already exists"))
w.WriteHeader(http.StatusMethodNotAllowed)
return
}

Expand Down Expand Up @@ -141,7 +141,7 @@ func deleteEvent(w http.ResponseWriter, r *http.Request) {
if string(bodyBytes) == "" {
log.Printf("Event with ID %s does not exist exists", eventID.ID)
w.Header().Set("Content-Type", "application/json")
w.Write([]byte("Event does not exists"))
w.WriteHeader(http.StatusNotFound)
return
}

Expand All @@ -157,7 +157,7 @@ func deleteEvent(w http.ResponseWriter, r *http.Request) {
return
}
log.Printf("Response after delete call: %s", resp.Status)

w.WriteHeader(http.StatusNoContent)
defer resp.Body.Close()
eventsCounter.Add(context.Background(), -1)
}
Expand Down Expand Up @@ -230,7 +230,7 @@ func updateEvent(w http.ResponseWriter, r *http.Request) {
if string(bodyBytes) == "" {
log.Printf("Event with ID %s does not exists", id)
w.Header().Set("Content-Type", "application/json")
w.Write([]byte("Event does not exists"))
w.WriteHeader(http.StatusNotFound)
return
}

Expand Down

0 comments on commit 4074ee2

Please sign in to comment.