mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-26 05:51:29 +00:00
feature(services): better error reporting in disable and enable service
This commit is contained in:
parent
2e59e7e880
commit
f5999516fa
|
@ -48,14 +48,22 @@ class ServicesMutations:
|
||||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||||
def enable_service(self, service_id: str) -> ServiceMutationReturn:
|
def enable_service(self, service_id: str) -> ServiceMutationReturn:
|
||||||
"""Enable service."""
|
"""Enable service."""
|
||||||
service = get_service_by_id(service_id)
|
try:
|
||||||
if service is None:
|
service = get_service_by_id(service_id)
|
||||||
|
if service is None:
|
||||||
|
return ServiceMutationReturn(
|
||||||
|
success=False,
|
||||||
|
message="Service not found.",
|
||||||
|
code=404,
|
||||||
|
)
|
||||||
|
service.enable()
|
||||||
|
except Exception as e:
|
||||||
return ServiceMutationReturn(
|
return ServiceMutationReturn(
|
||||||
success=False,
|
success=False,
|
||||||
message="Service not found.",
|
message=format_error(e),
|
||||||
code=404,
|
code=400,
|
||||||
)
|
)
|
||||||
service.enable()
|
|
||||||
return ServiceMutationReturn(
|
return ServiceMutationReturn(
|
||||||
success=True,
|
success=True,
|
||||||
message="Service enabled.",
|
message="Service enabled.",
|
||||||
|
@ -66,14 +74,21 @@ class ServicesMutations:
|
||||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||||
def disable_service(self, service_id: str) -> ServiceMutationReturn:
|
def disable_service(self, service_id: str) -> ServiceMutationReturn:
|
||||||
"""Disable service."""
|
"""Disable service."""
|
||||||
service = get_service_by_id(service_id)
|
try:
|
||||||
if service is None:
|
service = get_service_by_id(service_id)
|
||||||
|
if service is None:
|
||||||
|
return ServiceMutationReturn(
|
||||||
|
success=False,
|
||||||
|
message="Service not found.",
|
||||||
|
code=404,
|
||||||
|
)
|
||||||
|
service.disable()
|
||||||
|
except Exception as e:
|
||||||
return ServiceMutationReturn(
|
return ServiceMutationReturn(
|
||||||
success=False,
|
success=False,
|
||||||
message="Service not found.",
|
message=format_error(e),
|
||||||
code=404,
|
code=400,
|
||||||
)
|
)
|
||||||
service.disable()
|
|
||||||
return ServiceMutationReturn(
|
return ServiceMutationReturn(
|
||||||
success=True,
|
success=True,
|
||||||
message="Service disabled.",
|
message="Service disabled.",
|
||||||
|
@ -177,3 +192,7 @@ class ServicesMutations:
|
||||||
service=service_to_graphql_service(service),
|
service=service_to_graphql_service(service),
|
||||||
job=job_to_api_job(job),
|
job=job_to_api_job(job),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def format_error(e: Exception) -> str:
|
||||||
|
return type(e).__name__ + ": " + str(e)
|
||||||
|
|
Loading…
Reference in a new issue