From b065de784c035ae9640b2957a4f5995fc497df07 Mon Sep 17 00:00:00 2001 From: Mojtaba Date: Mon, 11 Dec 2023 19:27:06 +0100 Subject: [PATCH] fix: better err propagation for stop & start service --- api/v1/net_services_utils.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/api/v1/net_services_utils.go b/api/v1/net_services_utils.go index 6f70642..c5e7003 100644 --- a/api/v1/net_services_utils.go +++ b/api/v1/net_services_utils.go @@ -22,10 +22,15 @@ func netServiceStart(resp http.ResponseWriter, ns *netRestrictService, ifaceName } if err := ns.Start(ifaceName); err != nil { + slug := SlugServiceStartFailed + if err == ErrServiceNotInitialized { + slug = SlugServiceNotInitialized + } + sendJSONError(resp, MetaMessage{ Type: APIMetaMessageTypeError, - Slug: SlugServiceStartFailed, + Slug: slug, Title: "Service start failed", Message: err.Error(), }, @@ -42,10 +47,15 @@ func netServiceStop(resp http.ResponseWriter, ns *netRestrictService) error { } if err := ns.Stop(); err != nil { + slug := SlugServiceStopFailed + if err == ErrServiceNotStarted { + slug = SlugServiceNotStarted + } + sendJSONError(resp, MetaMessage{ Type: APIMetaMessageTypeError, - Slug: SlugServiceStopFailed, + Slug: slug, Title: "Service stop failed", Message: err.Error(), },