@@ -3,6 +3,7 @@ package accounts
33import (
44 "context"
55 "encoding/json"
6+ "fmt"
67 "net/http"
78 "net/netip"
89 "time"
@@ -12,11 +13,11 @@ import (
1213 goversion "github.com/hashicorp/go-version"
1314 "github.com/netbirdio/netbird/management/server/account"
1415 nbcontext "github.com/netbirdio/netbird/management/server/context"
16+ "github.com/netbirdio/netbird/management/server/settings"
17+ "github.com/netbirdio/netbird/management/server/types"
1518 "github.com/netbirdio/netbird/shared/management/http/api"
1619 "github.com/netbirdio/netbird/shared/management/http/util"
17- "github.com/netbirdio/netbird/management/server/settings"
1820 "github.com/netbirdio/netbird/shared/management/status"
19- "github.com/netbirdio/netbird/management/server/types"
2021)
2122
2223const (
@@ -163,7 +164,7 @@ func (h *handler) getAllAccounts(w http.ResponseWriter, r *http.Request) {
163164 util .WriteJSONObject (r .Context (), w , []* api.Account {resp })
164165}
165166
166- func (h * handler ) updateAccountRequestSettings (req api.PutApiAccountsAccountIdJSONRequestBody , w http. ResponseWriter ) * types.Settings {
167+ func (h * handler ) updateAccountRequestSettings (req api.PutApiAccountsAccountIdJSONRequestBody ) ( * types.Settings , error ) {
167168 returnSettings := & types.Settings {
168169 PeerLoginExpirationEnabled : req .Settings .PeerLoginExpirationEnabled ,
169170 PeerLoginExpiration : time .Duration (float64 (time .Second .Nanoseconds ()) * float64 (req .Settings .PeerLoginExpiration )),
@@ -209,12 +210,11 @@ func (h *handler) updateAccountRequestSettings(req api.PutApiAccountsAccountIdJS
209210 err == nil {
210211 returnSettings .AutoUpdateVersion = * req .Settings .AutoUpdateVersion
211212 } else if * req .Settings .AutoUpdateVersion != "" {
212- util .WriteErrorResponse ("Invalid AutoUpdateVersion" , http .StatusBadRequest , w )
213- return nil
213+ return nil , fmt .Errorf ("invalid AutoUpdateVersion" )
214214 }
215215 }
216216
217- return returnSettings
217+ return returnSettings , nil
218218}
219219
220220// updateAccount is HTTP PUT handler that updates the provided account. Updates only account settings (server.Settings)
@@ -241,9 +241,9 @@ func (h *handler) updateAccount(w http.ResponseWriter, r *http.Request) {
241241 return
242242 }
243243
244- settings := h .updateAccountRequestSettings (req , w )
245- if settings = = nil {
246- return
244+ settings , err := h .updateAccountRequestSettings (req )
245+ if err ! = nil {
246+ util . WriteError ( r . Context (), err , w )
247247 }
248248 if req .Settings .NetworkRange != nil && * req .Settings .NetworkRange != "" {
249249 prefix , err := netip .ParsePrefix (* req .Settings .NetworkRange )
0 commit comments