improved api error handling

This commit is contained in:
yusing
2025-01-05 00:02:31 +08:00
parent 0e886f5ddf
commit 55134c8426
4 changed files with 17 additions and 20 deletions

View File

@@ -34,7 +34,7 @@ func List(w http.ResponseWriter, r *http.Request) {
switch what {
case ListRoute:
if route := listRoute(which); route == nil {
http.Error(w, "not found", http.StatusNotFound)
http.NotFound(w, r)
return
} else {
U.RespondJSON(w, r, route)
@@ -59,10 +59,7 @@ func List(w http.ResponseWriter, r *http.Request) {
}
func listRoute(which string) any {
if which == "" {
which = "all"
}
if which == "all" {
if which == "" || which == "all" {
return config.RoutesByAlias()
}
routes := config.RoutesByAlias()