Maintenance: improve error wrapping
This commit is contained in:
@@ -3,6 +3,7 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -51,7 +52,7 @@ func (s *server) Run(ctx context.Context, done chan<- struct{}) {
|
||||
}()
|
||||
s.logger.Info("listening on %s", s.address)
|
||||
err := server.ListenAndServe()
|
||||
if err != nil && ctx.Err() != context.Canceled {
|
||||
if err != nil && errors.Is(ctx.Err(), context.Canceled) {
|
||||
s.logger.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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