@@ -3,6 +3,7 @@ package accounts
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
+ "fmt"
6
7
"net/http"
7
8
"net/netip"
8
9
"time"
@@ -12,11 +13,11 @@ import (
12
13
goversion "github.com/hashicorp/go-version"
13
14
"github.com/netbirdio/netbird/management/server/account"
14
15
nbcontext "github.com/netbirdio/netbird/management/server/context"
16
+ "github.com/netbirdio/netbird/management/server/settings"
17
+ "github.com/netbirdio/netbird/management/server/types"
15
18
"github.com/netbirdio/netbird/shared/management/http/api"
16
19
"github.com/netbirdio/netbird/shared/management/http/util"
17
- "github.com/netbirdio/netbird/management/server/settings"
18
20
"github.com/netbirdio/netbird/shared/management/status"
19
- "github.com/netbirdio/netbird/management/server/types"
20
21
)
21
22
22
23
const (
@@ -163,7 +164,7 @@ func (h *handler) getAllAccounts(w http.ResponseWriter, r *http.Request) {
163
164
util .WriteJSONObject (r .Context (), w , []* api.Account {resp })
164
165
}
165
166
166
- func (h * handler ) updateAccountRequestSettings (req api.PutApiAccountsAccountIdJSONRequestBody , w http. ResponseWriter ) * types.Settings {
167
+ func (h * handler ) updateAccountRequestSettings (req api.PutApiAccountsAccountIdJSONRequestBody ) ( * types.Settings , error ) {
167
168
returnSettings := & types.Settings {
168
169
PeerLoginExpirationEnabled : req .Settings .PeerLoginExpirationEnabled ,
169
170
PeerLoginExpiration : time .Duration (float64 (time .Second .Nanoseconds ()) * float64 (req .Settings .PeerLoginExpiration )),
@@ -209,12 +210,11 @@ func (h *handler) updateAccountRequestSettings(req api.PutApiAccountsAccountIdJS
209
210
err == nil {
210
211
returnSettings .AutoUpdateVersion = * req .Settings .AutoUpdateVersion
211
212
} else if * req .Settings .AutoUpdateVersion != "" {
212
- util .WriteErrorResponse ("Invalid AutoUpdateVersion" , http .StatusBadRequest , w )
213
- return nil
213
+ return nil , fmt .Errorf ("invalid AutoUpdateVersion" )
214
214
}
215
215
}
216
216
217
- return returnSettings
217
+ return returnSettings , nil
218
218
}
219
219
220
220
// 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) {
241
241
return
242
242
}
243
243
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 )
247
247
}
248
248
if req .Settings .NetworkRange != nil && * req .Settings .NetworkRange != "" {
249
249
prefix , err := netip .ParsePrefix (* req .Settings .NetworkRange )
0 commit comments