diff --git a/src/servala/core/models/organization.py b/src/servala/core/models/organization.py
index 57cd660..b8a4e2a 100644
--- a/src/servala/core/models/organization.py
+++ b/src/servala/core/models/organization.py
@@ -4,7 +4,6 @@ from django.conf import settings
from django.db import models, transaction
from django.utils.functional import cached_property
from django.utils.text import slugify
-from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django_scopes import ScopedManager, scopes_disabled
@@ -75,14 +74,6 @@ class Organization(ServalaModelMixin, models.Model):
user=user, organization=self, role=OrganizationRole.OWNER
)
- def add_support_message(self, message):
- support_message = _(
- "Need help? We're happy to help via the support form."
- ).format(support_url=self.urls.support)
- return mark_safe(
- f'{message} {support_message}'
- )
-
@classmethod
@transaction.atomic
def create_organization(cls, instance, owner):
diff --git a/src/servala/core/models/service.py b/src/servala/core/models/service.py
index 4c6ecd0..362661b 100644
--- a/src/servala/core/models/service.py
+++ b/src/servala/core/models/service.py
@@ -1,7 +1,5 @@
import copy
-import html
import json
-import re
import kubernetes
import rules
@@ -12,7 +10,6 @@ from django.core.exceptions import ValidationError
from django.db import IntegrityError, models, transaction
from django.utils import timezone
from django.utils.functional import cached_property
-from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from encrypted_fields.fields import EncryptedJSONField
from kubernetes import client, config
@@ -606,58 +603,6 @@ class ServiceInstance(ServalaModelMixin, models.Model):
spec_data = prune_empty_data(spec_data)
return spec_data
- @classmethod
- def _format_kubernetes_error(cls, error_message):
- if not error_message:
- return {"message": "", "errors": None, "has_list": False}
-
- error_message = str(error_message).strip()
-
- # Pattern to match validation errors in brackets like [error1, error2, error3]
- pattern = r"\[([^\]]+)\]"
- match = re.search(pattern, error_message)
-
- if not match:
- return {"message": error_message, "errors": None, "has_list": False}
-
- errors_text = match.group(1).strip()
-
- if "," not in errors_text:
- return {"message": error_message, "errors": None, "has_list": False}
-
- errors = [error.strip().strip("\"'") for error in errors_text.split(",")]
- errors = [error for error in errors if error]
-
- if len(errors) <= 1:
- return {"message": error_message, "errors": None, "has_list": False}
-
- base_message = re.sub(pattern, "", error_message).strip()
- base_message = base_message.rstrip(":").strip()
-
- return {"message": base_message, "errors": errors, "has_list": True}
-
- @classmethod
- def _safe_format_error(cls, error_data):
- if not isinstance(error_data, dict):
- return html.escape(str(error_data))
-
- if not error_data.get("has_list", False):
- return html.escape(error_data.get("message", ""))
-
- message = html.escape(error_data.get("message", ""))
- errors = error_data.get("errors", [])
-
- if not errors:
- return message
-
- escaped_errors = [html.escape(str(error)) for error in errors]
- error_items = "".join(f"
{error}" for error in escaped_errors)
-
- if message:
- return mark_safe(f"{message}")
- else:
- return mark_safe(f"")
-
@classmethod
def create_instance(cls, name, organization, context, created_by, spec_data):
# Ensure the namespace exists
@@ -670,10 +615,11 @@ class ServiceInstance(ServalaModelMixin, models.Model):
context=context,
)
except IntegrityError:
- message = _(
- "An instance with this name already exists in this organization. Please choose a different name."
+ raise ValidationError(
+ _(
+ "An instance with this name already exists in this organization. Please choose a different name."
+ )
)
- raise ValidationError(organization.add_support_message(message))
try:
spec_data = cls._prepare_spec_data(spec_data)
@@ -711,25 +657,10 @@ class ServiceInstance(ServalaModelMixin, models.Model):
try:
error_body = json.loads(e.body)
reason = error_body.get("message", str(e))
- error_data = cls._format_kubernetes_error(reason)
- formatted_reason = cls._safe_format_error(error_data)
- message = _("Error reported by control plane: {reason}").format(
- reason=formatted_reason
- )
- raise ValidationError(organization.add_support_message(message))
+ raise ValidationError(_("Kubernetes API error: {}").format(reason))
except (ValueError, TypeError):
- error_data = cls._format_kubernetes_error(str(e))
- formatted_error = cls._safe_format_error(error_data)
- message = _("Error reported by control plane: {error}").format(
- error=formatted_error
- )
- raise ValidationError(organization.add_support_message(message))
- error_data = cls._format_kubernetes_error(str(e))
- formatted_error = cls._safe_format_error(error_data)
- message = _("Error creating instance: {error}").format(
- error=formatted_error
- )
- raise ValidationError(organization.add_support_message(message))
+ raise ValidationError(_("Kubernetes API error: {}").format(str(e)))
+ raise ValidationError(_("Error creating instance: {}").format(str(e)))
return instance
def update_spec(self, spec_data, updated_by):
@@ -750,33 +681,29 @@ class ServiceInstance(ServalaModelMixin, models.Model):
self.save() # Updates updated_at timestamp
except ApiException as e:
if e.status == 404:
- message = _(
- "Service instance not found in control plane. It may have been deleted externally."
+ raise ValidationError(
+ _(
+ "Service instance not found in Kubernetes. It may have been deleted externally."
+ )
)
- raise ValidationError(self.organization.add_support_message(message))
try:
error_body = json.loads(e.body)
reason = error_body.get("message", str(e))
- error_data = self._format_kubernetes_error(reason)
- formatted_reason = self._safe_format_error(error_data)
- message = _(
- "Error reported by control plane while updating instance: {reason}"
- ).format(reason=formatted_reason)
- raise ValidationError(self.organization.add_support_message(message))
+ raise ValidationError(
+ _("Kubernetes API error updating instance: {error}").format(
+ error=reason
+ )
+ )
except (ValueError, TypeError):
- error_data = self._format_kubernetes_error(str(e))
- formatted_error = self._safe_format_error(error_data)
- message = _(
- "Error reported by control plane while updating instance: {error}"
- ).format(error=formatted_error)
- raise ValidationError(self.organization.add_support_message(message))
+ raise ValidationError(
+ _("Kubernetes API error updating instance: {error}").format(
+ error=str(e)
+ )
+ )
except Exception as e:
- error_data = self._format_kubernetes_error(str(e))
- formatted_error = self._safe_format_error(error_data)
- message = _("Error updating instance: {error}").format(
- error=formatted_error
+ raise ValidationError(
+ _("Error updating instance: {error}").format(error=str(e))
)
- raise ValidationError(self.organization.add_support_message(message))
@transaction.atomic
def delete_instance(self, user):
diff --git a/src/servala/frontend/templates/includes/k8s_error.html b/src/servala/frontend/templates/includes/k8s_error.html
deleted file mode 100644
index f97474d..0000000
--- a/src/servala/frontend/templates/includes/k8s_error.html
+++ /dev/null
@@ -1,14 +0,0 @@
-{% if show_error %}
-
- {% if has_list %}
- {% if message %}{{ message }}{% endif %}
-
- {% for error in errors %}
- - {{ error }}
- {% endfor %}
-
- {% else %}
- {{ message }}
- {% endif %}
-
-{% endif %}
diff --git a/src/servala/frontend/templates/includes/message.html b/src/servala/frontend/templates/includes/message.html
index d5debc9..59260d2 100644
--- a/src/servala/frontend/templates/includes/message.html
+++ b/src/servala/frontend/templates/includes/message.html
@@ -9,7 +9,7 @@