Fix: Polish bootstrap flow

This commit is contained in:
MangoPig
2026-06-19 22:47:12 +01:00
parent 35c1a861f5
commit 699574e345
6 changed files with 205 additions and 99 deletions

View File

@@ -20,6 +20,7 @@ type bootstrapInstanceStepRequest struct {
type bootstrapModeStepRequest struct {
Mode string `json:"mode"`
Name string `json:"name"`
}
type bootstrapAdminStepRequest struct {
@@ -234,13 +235,19 @@ func (routes apiRoutes) handleBootstrapModeStep(w http.ResponseWriter, r *http.R
return
}
payload.Mode = strings.ToLower(strings.TrimSpace(payload.Mode))
payload.Name = strings.TrimSpace(payload.Name)
if payload.Mode != "personal" && payload.Mode != "organizational" {
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Mode must be either 'personal' or 'organizational'.")
return
}
record, err := routes.bootstrapService().SaveMode(r.Context(), bootstrapservice.SaveModeInput{Mode: payload.Mode})
if payload.Name == "" {
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Name is required.")
return
}
record, err := routes.bootstrapService().SaveMode(r.Context(), bootstrapservice.SaveModeInput{Mode: payload.Mode, Name: payload.Name})
if err != nil {
routes.writeBootstrapPersistenceError(w, r, err)
return
@@ -356,7 +363,11 @@ func (routes apiRoutes) writeBootstrapPersistenceError(w http.ResponseWriter, r
WriteError(w, http.StatusConflict, RequestIDFromContext(r.Context()), "bootstrap_prerequisite_missing", err.Error())
default:
routes.cfg.Logger.Error("persist bootstrap step", "error", err, "path", r.URL.Path)
WriteError(w, http.StatusInternalServerError, RequestIDFromContext(r.Context()), "bootstrap_persist_failed", "Failed to persist bootstrap data.")
message := "Failed to persist bootstrap data."
if routes.cfg.Config.IsDevelopment() {
message = message + " " + err.Error()
}
WriteError(w, http.StatusInternalServerError, RequestIDFromContext(r.Context()), "bootstrap_persist_failed", message)
}
}