Skip to content

Commit 9f774c4

Browse files
committed
Fix: Error return value of w.Write is not checked
1 parent 0c158f8 commit 9f774c4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

main.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,17 @@ func main() {
149149
// serveHome serves the main HTML page.
150150
func serveHome(w http.ResponseWriter, r *http.Request) {
151151
w.Header().Set("Content-Type", "text/html")
152-
w.Write(indexHTML)
152+
if _, err := w.Write(indexHTML); err != nil {
153+
log.Printf("Could not write response: %v", err)
154+
}
153155
}
154156

155157
// getMapSources serves the available map sources as JSON.
156158
func getMapSources(w http.ResponseWriter, r *http.Request) {
157159
w.Header().Set("Content-Type", "application/json")
158-
w.Write(mapSourcesJSON)
160+
if _, err := w.Write(mapSourcesJSON); err != nil {
161+
log.Printf("Could not write response: %v", err)
162+
}
159163
}
160164

161165
// wsHandler handles WebSocket connections.
@@ -703,7 +707,9 @@ func getCachedTiles(w http.ResponseWriter, r *http.Request) {
703707
}
704708

705709
w.Header().Set("Content-Type", "application/json")
706-
json.NewEncoder(w).Encode(cachedTiles)
710+
if err := json.NewEncoder(w).Encode(cachedTiles); err != nil {
711+
http.Error(w, fmt.Sprintf("Error encoding cached tiles: %v", err), http.StatusInternalServerError)
712+
}
707713
}
708714

709715
// getStyleName returns the name of the map style for a given URL.

0 commit comments

Comments
 (0)