refactor: improve error handling, validation and proper cleanup

This commit is contained in:
yusing
2026-01-25 19:18:14 +08:00
parent 0633cacb2a
commit 73cba8b508
12 changed files with 52 additions and 30 deletions

View File

@@ -218,7 +218,7 @@ func (r *Route) validate() gperr.Error {
r.Proxmox.VMName = res.Name
if r.Host == DefaultHost {
containerName := r.Idlewatcher.ContainerName()
containerName := res.Name
// get ip addresses of the vmid
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
@@ -336,7 +336,7 @@ func (r *Route) validate() gperr.Error {
}
}
if r.Proxmox == nil && r.Container == nil {
if r.Proxmox == nil && r.Container == nil && r.ProxyURL != nil {
proxmoxProviders := config.WorkingState.Load().Value().Providers.Proxmox
if len(proxmoxProviders) > 0 {
// it's fine if ip is nil

View File

@@ -79,6 +79,10 @@ var commands = map[string]struct {
},
build: func(args any) CommandHandler {
return NonTerminatingCommand(func(w http.ResponseWriter, r *http.Request) error {
if authHandler == nil {
http.Error(w, "Auth handler not initialized", http.StatusInternalServerError)
return errTerminated
}
if !authHandler(w, r) {
return errTerminated
}