Fix organization deletion error messages (#107380)

* Fix organization deletion error messages

- Improve error message clarity when attempting to delete active organization
- Fix incorrect 'Failed to update organization' message to 'Failed to delete organization'
- Update comment to be more precise about the check being performed

Fixes #92792

* Improve error handling in organization deletion service

- Add contextual error message when dashboard deletion fails during org deletion
- Include organization ID in error message for better debugging
- Import fmt package for error formatting

This helps administrators understand which specific organization failed
during the deletion process when dashboard cleanup encounters issues.

* Fix typo in unified resource access error message

Change 'Namespace missmatch' to 'Namespace mismatch' for correct spelling.
This commit is contained in:
Jo
2025-06-30 13:58:37 +02:00
committed by GitHub
parent 7ebea688ef
commit 7940da4803
3 changed files with 7 additions and 6 deletions
+3 -3
View File
@@ -292,16 +292,16 @@ func (hs *HTTPServer) DeleteOrgByID(c *contextmodel.ReqContext) response.Respons
if err != nil {
return response.Error(http.StatusBadRequest, "orgId is invalid", err)
}
// before deleting an org, check if user does not belong to the current org
// before deleting an org, check if user is not active in the org
if c.GetOrgID() == orgID {
return response.Error(http.StatusBadRequest, "Can not delete org for current user", nil)
return response.Error(http.StatusBadRequest, "Cannot delete your active organization. Please switch to a different organization first.", nil)
}
if err := hs.orgDeletionService.Delete(c.Req.Context(), &org.DeleteOrgCommand{ID: orgID}); err != nil {
if errors.Is(err, org.ErrOrgNotFound) {
return response.Error(http.StatusNotFound, "Failed to delete organization. ID not found", nil)
}
return response.Error(http.StatusInternalServerError, "Failed to update organization", err)
return response.Error(http.StatusInternalServerError, "Failed to delete organization", err)
}
return response.Success("Organization deleted")
}