return empty domain list when none in database

This commit is contained in:
Alisdair MacLeod
2026-01-27 16:34:37 +00:00
parent 6e4e1386e7
commit 7b3523e25e
3 changed files with 11 additions and 3 deletions

View File

@@ -56,6 +56,10 @@ func (h *handler) getAllDomains(w http.ResponseWriter, r *http.Request) {
}
domains, err := h.manager.GetDomains(r.Context(), userAuth.AccountId)
if err != nil {
util.WriteError(r.Context(), err, w)
return
}
var ret []api.ReverseProxyDomain
for _, d := range domains {

View File

@@ -6,6 +6,7 @@ import (
"net"
"github.com/netbirdio/netbird/management/server/types"
"github.com/netbirdio/netbird/shared/management/status"
)
type domainType string
@@ -58,8 +59,10 @@ func (m Manager) GetDomains(ctx context.Context, accountID string) ([]*Domain, e
return nil, fmt.Errorf("list free domains: %w", err)
}
domains, err := m.store.ListCustomDomains(ctx, accountID)
if err != nil {
// TODO: check for "no records" type error. Because that is a success condition.
if statusErr, ok := status.FromError(err); ok && statusErr.Type() == status.NotFound {
// This is fine, make sure domains are correctly set and continue.
domains = make([]*Domain, 0)
} else if err != nil {
return nil, fmt.Errorf("list custom domains: %w", err)
}

View File

@@ -30,7 +30,8 @@ func RegisterEndpoints(manager reverseproxy.Manager, domainManager domain.Manage
router.HandleFunc("/reverse-proxies/{proxyId}", h.deleteReverseProxy).Methods("DELETE", "OPTIONS")
// Hang domain endpoints off the main router here.
domain.RegisterEndpoints(router.PathPrefix("/reverse-proxies").Subrouter(), domainManager)
domainRouter := router.PathPrefix("/reverse-proxies").Subrouter()
domain.RegisterEndpoints(domainRouter, domainManager)
}
func (h *handler) getAllReverseProxies(w http.ResponseWriter, r *http.Request) {