Skip to content

Commit 3cc852e

Browse files
committed
incus-osd/rest: Correct several BadRequest errors to a more proper InternalError
Signed-off-by: Mathias Gibbens <mathias.gibbens@futurfusion.io>
1 parent 6eeb1c6 commit 3cc852e

File tree

7 files changed

+35
-35
lines changed

7 files changed

+35
-35
lines changed

incus-osd/internal/rest/api_applications.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ func (s *Server) apiApplicationsFactoryReset(w http.ResponseWriter, r *http.Requ
8686
// Load the application.
8787
app, err := applications.Load(r.Context(), s.state, name)
8888
if err != nil {
89-
_ = response.BadRequest(err).Render(w)
89+
_ = response.InternalError(err).Render(w)
9090

9191
return
9292
}
9393

9494
// Do the factory reset.
9595
err = app.FactoryReset(r.Context())
9696
if err != nil {
97-
_ = response.BadRequest(err).Render(w)
97+
_ = response.InternalError(err).Render(w)
9898

9999
return
100100
}
@@ -124,15 +124,15 @@ func (s *Server) apiApplicationsRestart(w http.ResponseWriter, r *http.Request)
124124
// Load the application.
125125
app, err := applications.Load(r.Context(), s.state, name)
126126
if err != nil {
127-
_ = response.BadRequest(err).Render(w)
127+
_ = response.InternalError(err).Render(w)
128128

129129
return
130130
}
131131

132132
// Trigger the restart.
133133
err = app.Restart(r.Context(), s.state.Applications[name].State.Version)
134134
if err != nil {
135-
_ = response.BadRequest(err).Render(w)
135+
_ = response.InternalError(err).Render(w)
136136

137137
return
138138
}
@@ -162,7 +162,7 @@ func (s *Server) apiApplicationsBackup(w http.ResponseWriter, r *http.Request) {
162162
// Load the application.
163163
app, err := applications.Load(r.Context(), s.state, name)
164164
if err != nil {
165-
_ = response.BadRequest(err).Render(w)
165+
_ = response.InternalError(err).Render(w)
166166

167167
return
168168
}
@@ -177,7 +177,7 @@ func (s *Server) apiApplicationsBackup(w http.ResponseWriter, r *http.Request) {
177177
// how large the archive might be and we don't want to DOS ourselves.
178178
err = app.GetBackup(io.Discard, complete == "true")
179179
if err != nil {
180-
_ = response.BadRequest(err).Render(w)
180+
_ = response.InternalError(err).Render(w)
181181

182182
return
183183
}
@@ -190,7 +190,7 @@ func (s *Server) apiApplicationsBackup(w http.ResponseWriter, r *http.Request) {
190190

191191
err = app.GetBackup(w, complete == "true")
192192
if err != nil {
193-
_ = response.BadRequest(err).Render(w)
193+
_ = response.InternalError(err).Render(w)
194194

195195
return
196196
}
@@ -218,15 +218,15 @@ func (s *Server) apiApplicationsRestore(w http.ResponseWriter, r *http.Request)
218218
// Load the application.
219219
app, err := applications.Load(r.Context(), s.state, name)
220220
if err != nil {
221-
_ = response.BadRequest(err).Render(w)
221+
_ = response.InternalError(err).Render(w)
222222

223223
return
224224
}
225225

226226
// Restore the application's backup.
227227
err = app.RestoreBackup(r.Context(), r.Body)
228228
if err != nil {
229-
_ = response.BadRequest(err).Render(w)
229+
_ = response.InternalError(err).Render(w)
230230

231231
return
232232
}
@@ -238,7 +238,7 @@ func (s *Server) apiApplicationsRestore(w http.ResponseWriter, r *http.Request)
238238

239239
err = s.state.Save()
240240
if err != nil {
241-
_ = response.BadRequest(err).Render(w)
241+
_ = response.InternalError(err).Render(w)
242242

243243
return
244244
}

incus-osd/internal/rest/api_system_backup.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ func (s *Server) apiSystemBackup(w http.ResponseWriter, r *http.Request) {
2020
// Make sure we have the current state written to disk prior to backup.
2121
err := s.state.Save()
2222
if err != nil {
23-
_ = response.BadRequest(err).Render(w)
23+
_ = response.InternalError(err).Render(w)
2424

2525
return
2626
}
2727

2828
archive, err := backup.GetOSBackup()
2929
if err != nil {
30-
_ = response.BadRequest(err).Render(w)
30+
_ = response.InternalError(err).Render(w)
3131

3232
return
3333
}
@@ -36,7 +36,7 @@ func (s *Server) apiSystemBackup(w http.ResponseWriter, r *http.Request) {
3636

3737
_, err = w.Write(archive)
3838
if err != nil {
39-
_ = response.BadRequest(err).Render(w)
39+
_ = response.InternalError(err).Render(w)
4040

4141
return
4242
}
@@ -56,7 +56,7 @@ func (s *Server) apiSystemRestore(w http.ResponseWriter, r *http.Request) {
5656

5757
err := backup.ApplyOSBackup(r.Context(), s.state, r.Body, skip)
5858
if err != nil {
59-
_ = response.BadRequest(err).Render(w)
59+
_ = response.InternalError(err).Render(w)
6060

6161
return
6262
}

incus-osd/internal/rest/api_system_network.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (s *Server) apiSystemNetwork(w http.ResponseWriter, r *http.Request) {
2222
// Refresh network state; needed to get current LLDP info.
2323
err := systemd.UpdateNetworkState(r.Context(), &s.state.System.Network)
2424
if err != nil {
25-
_ = response.BadRequest(err).Render(w)
25+
_ = response.InternalError(err).Render(w)
2626

2727
return
2828
}
@@ -53,7 +53,7 @@ func (s *Server) apiSystemNetwork(w http.ResponseWriter, r *http.Request) {
5353
err = systemd.ApplyNetworkConfiguration(r.Context(), s.state, newConfig.Config, 30*time.Second, false, providers.Refresh)
5454
if err != nil {
5555
slog.ErrorContext(r.Context(), "Failed to update network configuration: "+err.Error())
56-
_ = response.BadRequest(err).Render(w)
56+
_ = response.InternalError(err).Render(w)
5757

5858
return
5959
}

incus-osd/internal/rest/api_system_provider.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ func (s *Server) apiSystemProvider(w http.ResponseWriter, r *http.Request) {
3232
// Load the current provider and deregister it.
3333
p, err := providers.Load(r.Context(), s.state)
3434
if err != nil {
35-
_ = response.BadRequest(err).Render(w)
35+
_ = response.InternalError(err).Render(w)
3636

3737
return
3838
}
3939

4040
err = p.Deregister(r.Context())
4141
if err != nil {
42-
_ = response.BadRequest(err).Render(w)
42+
_ = response.InternalError(err).Render(w)
4343

4444
return
4545
}
@@ -52,7 +52,7 @@ func (s *Server) apiSystemProvider(w http.ResponseWriter, r *http.Request) {
5252
if err != nil {
5353
s.state.System.Provider.Config = oldConfig
5454
_ = s.state.Save()
55-
_ = response.BadRequest(err).Render(w)
55+
_ = response.InternalError(err).Render(w)
5656

5757
return
5858
}
@@ -61,7 +61,7 @@ func (s *Server) apiSystemProvider(w http.ResponseWriter, r *http.Request) {
6161
if err != nil {
6262
s.state.System.Provider.Config = oldConfig
6363
_ = s.state.Save()
64-
_ = response.BadRequest(err).Render(w)
64+
_ = response.InternalError(err).Render(w)
6565

6666
return
6767
}

incus-osd/internal/rest/api_system_reset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (*Server) apiSystemFactoryReset(w http.ResponseWriter, r *http.Request) {
3636

3737
err = reset.PerformOSFactoryReset(r.Context(), resetData)
3838
if err != nil {
39-
_ = response.BadRequest(err).Render(w)
39+
_ = response.InternalError(err).Render(w)
4040

4141
return
4242
}

incus-osd/internal/rest/api_system_security.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (s *Server) apiSystemSecurity(w http.ResponseWriter, r *http.Request) {
3030
// Get Secure Boot state (we always expect this to be true).
3131
s.state.System.Security.State.SecureBootEnabled, err = secureboot.Enabled()
3232
if err != nil {
33-
_ = response.BadRequest(err).Render(w)
33+
_ = response.InternalError(err).Render(w)
3434

3535
return
3636
}
@@ -44,7 +44,7 @@ func (s *Server) apiSystemSecurity(w http.ResponseWriter, r *http.Request) {
4444
// Get zpool encryption keys.
4545
s.state.System.Security.State.PoolRecoveryKeys, err = zfs.GetZpoolEncryptionKeys()
4646
if err != nil {
47-
_ = response.BadRequest(err).Render(w)
47+
_ = response.InternalError(err).Render(w)
4848

4949
return
5050
}
@@ -61,7 +61,7 @@ func (s *Server) apiSystemSecurity(w http.ResponseWriter, r *http.Request) {
6161

6262
b, err := io.ReadAll(r.Body)
6363
if err != nil {
64-
_ = response.BadRequest(err).Render(w)
64+
_ = response.InternalError(err).Render(w)
6565

6666
return
6767
}
@@ -86,7 +86,7 @@ func (s *Server) apiSystemSecurity(w http.ResponseWriter, r *http.Request) {
8686
if !slices.Contains(securityStruct.Config.EncryptionRecoveryKeys, existingKey) {
8787
err := systemd.DeleteEncryptionKey(r.Context(), s.state, existingKey)
8888
if err != nil {
89-
_ = response.BadRequest(err).Render(w)
89+
_ = response.InternalError(err).Render(w)
9090

9191
return
9292
}
@@ -98,7 +98,7 @@ func (s *Server) apiSystemSecurity(w http.ResponseWriter, r *http.Request) {
9898
if !slices.Contains(s.state.System.Security.Config.EncryptionRecoveryKeys, newKey) {
9999
err := systemd.AddEncryptionKey(r.Context(), s.state, newKey)
100100
if err != nil {
101-
_ = response.BadRequest(err).Render(w)
101+
_ = response.InternalError(err).Render(w)
102102

103103
return
104104
}

incus-osd/internal/rest/api_system_storage.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (s *Server) apiSystemStorage(w http.ResponseWriter, r *http.Request) {
1919
case http.MethodGet:
2020
ret, err := storage.GetStorageInfo(r.Context())
2121
if err != nil {
22-
_ = response.BadRequest(err).Render(w)
22+
_ = response.InternalError(err).Render(w)
2323

2424
return
2525
}
@@ -36,7 +36,7 @@ func (s *Server) apiSystemStorage(w http.ResponseWriter, r *http.Request) {
3636

3737
b, err := io.ReadAll(r.Body)
3838
if err != nil {
39-
_ = response.BadRequest(err).Render(w)
39+
_ = response.InternalError(err).Render(w)
4040

4141
return
4242
}
@@ -65,7 +65,7 @@ func (s *Server) apiSystemStorage(w http.ResponseWriter, r *http.Request) {
6565
}
6666

6767
if err != nil {
68-
_ = response.BadRequest(err).Render(w)
68+
_ = response.InternalError(err).Render(w)
6969

7070
return
7171
}
@@ -97,7 +97,7 @@ func (*Server) apiSystemStorageDeletePool(w http.ResponseWriter, r *http.Request
9797

9898
b, err := io.ReadAll(r.Body)
9999
if err != nil {
100-
_ = response.BadRequest(err).Render(w)
100+
_ = response.InternalError(err).Render(w)
101101

102102
return
103103
}
@@ -124,7 +124,7 @@ func (*Server) apiSystemStorageDeletePool(w http.ResponseWriter, r *http.Request
124124
// Delete the pool.
125125
err = zfs.DestroyZpool(r.Context(), config.Name)
126126
if err != nil {
127-
_ = response.BadRequest(err).Render(w)
127+
_ = response.InternalError(err).Render(w)
128128

129129
return
130130
}
@@ -150,7 +150,7 @@ func (*Server) apiSystemStorageWipeDrive(w http.ResponseWriter, r *http.Request)
150150

151151
b, err := io.ReadAll(r.Body)
152152
if err != nil {
153-
_ = response.BadRequest(err).Render(w)
153+
_ = response.InternalError(err).Render(w)
154154

155155
return
156156
}
@@ -172,7 +172,7 @@ func (*Server) apiSystemStorageWipeDrive(w http.ResponseWriter, r *http.Request)
172172

173173
err = storage.WipeDrive(r.Context(), wipeStruct.ID)
174174
if err != nil {
175-
_ = response.BadRequest(err).Render(w)
175+
_ = response.InternalError(err).Render(w)
176176

177177
return
178178
}
@@ -198,7 +198,7 @@ func (*Server) apiSystemStorageImportEncryptionKey(w http.ResponseWriter, r *htt
198198

199199
b, err := io.ReadAll(r.Body)
200200
if err != nil {
201-
_ = response.BadRequest(err).Render(w)
201+
_ = response.InternalError(err).Render(w)
202202

203203
return
204204
}
@@ -226,7 +226,7 @@ func (*Server) apiSystemStorageImportEncryptionKey(w http.ResponseWriter, r *htt
226226

227227
err = storage.SetEncryptionKey(r.Context(), poolStruct.Name, poolStruct.EncryptionKey)
228228
if err != nil {
229-
_ = response.BadRequest(err).Render(w)
229+
_ = response.InternalError(err).Render(w)
230230

231231
return
232232
}

0 commit comments

Comments
 (0)