Skip to content

Commit

Permalink
fix: better err propagation for stop & start service
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-esk committed Dec 11, 2023
1 parent 456bae4 commit b065de7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions api/v1/net_services_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand All @@ -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(),
},
Expand Down

0 comments on commit b065de7

Please sign in to comment.