mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Remove string checking in API error handling
Use strongly typed errors to set HTTP status codes. Error interfaces are defined in the api/errors package and errors returned from controllers are checked against these interfaces. Errors can be wraeped in a pkg/errors.Causer, as long as somewhere in the line of causes one of the interfaces is implemented. The special error interfaces take precedence over Causer, meaning if both Causer and one of the new error interfaces are implemented, the Causer is not traversed. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
@@ -2,12 +2,10 @@ package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/errors"
|
||||
containerpkg "github.com/docker/docker/container"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -23,15 +21,14 @@ func (daemon *Daemon) ContainerStop(name string, seconds *int) error {
|
||||
return err
|
||||
}
|
||||
if !container.IsRunning() {
|
||||
err := fmt.Errorf("Container %s is already stopped", name)
|
||||
return errors.NewErrorWithStatusCode(err, http.StatusNotModified)
|
||||
return containerNotModifiedError{running: false}
|
||||
}
|
||||
if seconds == nil {
|
||||
stopTimeout := container.StopTimeout()
|
||||
seconds = &stopTimeout
|
||||
}
|
||||
if err := daemon.containerStop(container, *seconds); err != nil {
|
||||
return fmt.Errorf("Cannot stop container %s: %v", name, err)
|
||||
return errors.Wrapf(systemError{err}, "cannot stop container: %s", name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user