aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/api/datamaps.go
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-03-13 16:42:27 +0000
committerMatthew Lemon <y@yulqen.org>2024-03-13 16:42:27 +0000
commit033a6e69a473e44ccb7cd66295532846768af114 (patch)
tree5b72fad2e04f210bdf005e0c6014aae463384f3c /cmd/api/datamaps.go
parent5607c7558178c8cc84ee1ec3d7f4b39dbfc10f4f (diff)
Implements our own errors
Diffstat (limited to 'cmd/api/datamaps.go')
-rw-r--r--cmd/api/datamaps.go9
1 files changed, 3 insertions, 6 deletions
diff --git a/cmd/api/datamaps.go b/cmd/api/datamaps.go
index c58d811..10dfa38 100644
--- a/cmd/api/datamaps.go
+++ b/cmd/api/datamaps.go
@@ -29,8 +29,7 @@ func (app *application) createDatamapHandler(w http.ResponseWriter, r *http.Requ
// Parse the multipart form
err := r.ParseMultipartForm(10 << 20) // 10Mb max
if err != nil {
- http.Error(w, err.Error(), http.StatusBadRequest)
- return
+ app.serverErrorResponse(w, r, err)
}
// Get form values
@@ -77,8 +76,7 @@ func (app *application) createDatamapHandler(w http.ResponseWriter, r *http.Requ
err = app.writeJSONPretty(w, http.StatusOK, envelope{"datamap": dm}, nil)
if err != nil {
app.logger.Debug("writing out csv", "err", err)
- http.Error(w, "Cannot write output from parsed CSV", http.StatusInternalServerError)
- return
+ app.serverErrorResponse(w, r, err)
}
// fmt.Fprintf(w, "file successfully uploaded")
@@ -89,8 +87,7 @@ func (app *application) showDatamapHandler(w http.ResponseWriter, r *http.Reques
app.logger.Info("the id requested", "id", id)
id_int, err := strconv.ParseInt(id, 10, 64)
if err != nil || id_int < 1 {
- http.NotFound(w, r)
- return
+ app.notFoundResponse(w, r)
}
fmt.Fprintf(w, "show the details for datamap %d\n", id_int)
}