mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 20:11:30 +00:00
feature(services): better error reporting in disable and enable service
This commit is contained in:
parent
2e59e7e880
commit
f5999516fa
|
@ -48,6 +48,7 @@ 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."""
|
||||||
|
try:
|
||||||
service = get_service_by_id(service_id)
|
service = get_service_by_id(service_id)
|
||||||
if service is None:
|
if service is None:
|
||||||
return ServiceMutationReturn(
|
return ServiceMutationReturn(
|
||||||
|
@ -56,6 +57,13 @@ class ServicesMutations:
|
||||||
code=404,
|
code=404,
|
||||||
)
|
)
|
||||||
service.enable()
|
service.enable()
|
||||||
|
except Exception as e:
|
||||||
|
return ServiceMutationReturn(
|
||||||
|
success=False,
|
||||||
|
message=format_error(e),
|
||||||
|
code=400,
|
||||||
|
)
|
||||||
|
|
||||||
return ServiceMutationReturn(
|
return ServiceMutationReturn(
|
||||||
success=True,
|
success=True,
|
||||||
message="Service enabled.",
|
message="Service enabled.",
|
||||||
|
@ -66,6 +74,7 @@ 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."""
|
||||||
|
try:
|
||||||
service = get_service_by_id(service_id)
|
service = get_service_by_id(service_id)
|
||||||
if service is None:
|
if service is None:
|
||||||
return ServiceMutationReturn(
|
return ServiceMutationReturn(
|
||||||
|
@ -74,6 +83,12 @@ class ServicesMutations:
|
||||||
code=404,
|
code=404,
|
||||||
)
|
)
|
||||||
service.disable()
|
service.disable()
|
||||||
|
except Exception as e:
|
||||||
|
return ServiceMutationReturn(
|
||||||
|
success=False,
|
||||||
|
message=format_error(e),
|
||||||
|
code=400,
|
||||||
|
)
|
||||||
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