Maintenance: improve error wrapping
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
@@ -11,15 +12,16 @@ type statusWrapper struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
var errInvalidStatus = errors.New("invalid status")
|
||||
|
||||
func (sw *statusWrapper) getStatus() (status models.LoopStatus, err error) {
|
||||
status = models.LoopStatus(sw.Status)
|
||||
switch status {
|
||||
case constants.Stopped, constants.Running:
|
||||
return status, nil
|
||||
default:
|
||||
return "", fmt.Errorf(
|
||||
"invalid status %q: possible values are: %s, %s",
|
||||
sw.Status, constants.Stopped, constants.Running)
|
||||
return "", fmt.Errorf("%w: %s: possible values are: %s, %s",
|
||||
errInvalidStatus, sw.Status, constants.Stopped, constants.Running)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user