feature(services): better error reporting in disable and enable service

This commit is contained in:
Houkime 2023-11-22 14:47:57 +00:00
parent 2e59e7e880
commit f5999516fa

View file

@ -48,6 +48,7 @@ class ServicesMutations:
@strawberry.mutation(permission_classes=[IsAuthenticated])
def enable_service(self, service_id: str) -> ServiceMutationReturn:
"""Enable service."""
try:
service = get_service_by_id(service_id)
if service is None:
return ServiceMutationReturn(
@ -56,6 +57,13 @@ class ServicesMutations:
code=404,
)
service.enable()
except Exception as e:
return ServiceMutationReturn(
success=False,
message=format_error(e),
code=400,
)
return ServiceMutationReturn(
success=True,
message="Service enabled.",
@ -66,6 +74,7 @@ class ServicesMutations:
@strawberry.mutation(permission_classes=[IsAuthenticated])
def disable_service(self, service_id: str) -> ServiceMutationReturn:
"""Disable service."""
try:
service = get_service_by_id(service_id)
if service is None:
return ServiceMutationReturn(
@ -74,6 +83,12 @@ class ServicesMutations:
code=404,
)
service.disable()
except Exception as e:
return ServiceMutationReturn(
success=False,
message=format_error(e),
code=400,
)
return ServiceMutationReturn(
success=True,
message="Service disabled.",
@ -177,3 +192,7 @@ class ServicesMutations:
service=service_to_graphql_service(service),
job=job_to_api_job(job),
)
def format_error(e: Exception) -> str:
return type(e).__name__ + ": " + str(e)