Adding new errors and centralising handling

This commit is contained in:
2026-03-18 22:41:22 +00:00
parent 8749ff3c03
commit a33cedf09e
3 changed files with 77 additions and 10 deletions

View File

@@ -85,7 +85,7 @@ func (s *Server) getNotes(w http.ResponseWriter, r *http.Request) {
func (s *Server) createNote(w http.ResponseWriter, r *http.Request) {
note := struct {
Content string `json:"content"`
Title string `json:"title"`
Title string `json:"title"`
}{}
if err := json.NewDecoder(r.Body).Decode(&note); err != nil {
http.Error(w, "invalid request body", http.StatusBadRequest)
@@ -123,7 +123,7 @@ func (s *Server) updateNoteByID(w http.ResponseWriter, r *http.Request) {
}
note := struct {
Content string `json:"content"`
Title string `json:"title"`
Title string `json:"title"`
}{}
if err := json.NewDecoder(r.Body).Decode(&note); err != nil {
http.Error(w, "invalid request body", http.StatusBadRequest)