Skip to content

Commit 59b391a

Browse files
committed
web: return proper error codes
1 parent a8f2db8 commit 59b391a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: cmd/git-bundle-web-server/main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func serve(w http.ResponseWriter, r *http.Request) {
4242

4343
owner, repo, file, err := parseRoute(path)
4444
if err != nil {
45-
// TODO: report a failure to the user somehow. 404?
45+
w.WriteHeader(http.StatusNotFound)
4646
fmt.Printf("Failed to parse route: %s\n", err)
4747
return
4848
}
@@ -51,14 +51,14 @@ func serve(w http.ResponseWriter, r *http.Request) {
5151

5252
repos, err := core.GetRepositories()
5353
if err != nil {
54-
// TODO: report a 500
54+
w.WriteHeader(http.StatusInternalServerError)
5555
fmt.Printf("Failed to load routes\n")
5656
return
5757
}
5858

5959
repository, contains := repos[route]
6060
if !contains {
61-
// TODO: report a 404
61+
w.WriteHeader(http.StatusNotFound)
6262
fmt.Printf("Failed to get route out of repos\n")
6363
return
6464
}
@@ -70,7 +70,7 @@ func serve(w http.ResponseWriter, r *http.Request) {
7070
fileToServe := repository.WebDir + "/" + file
7171
data, err := os.ReadFile(fileToServe)
7272
if err != nil {
73-
// TODO: return a 404
73+
w.WriteHeader(http.StatusNotFound)
7474
fmt.Printf("Failed to read file\n")
7575
return
7676
}

0 commit comments

Comments
 (0)