diff --git a/api/container.go b/api/container.go index f6a8948..aed1a79 100644 --- a/api/container.go +++ b/api/container.go @@ -2,11 +2,13 @@ package api import ( "io" + "net/http" "github.com/cuigh/auxo/data" "github.com/cuigh/auxo/log" "github.com/cuigh/auxo/net/web" "github.com/cuigh/swirl/biz" + "github.com/cuigh/swirl/docker" "github.com/gobwas/ws" "github.com/gobwas/ws/wsutil" ) @@ -70,6 +72,9 @@ func containerFind(b biz.ContainerBiz) web.HandlerFunc { id := ctx.Query("id") container, raw, err := b.Find(node, id) if err != nil { + if docker.IsErrNotFound(err) { + return web.NewError(http.StatusNotFound, err.Error()) + } return err } return success(ctx, data.Map{"container": container, "raw": raw}) diff --git a/api/service.go b/api/service.go index 3133b32..7f2347e 100644 --- a/api/service.go +++ b/api/service.go @@ -1,9 +1,12 @@ package api import ( + "net/http" + "github.com/cuigh/auxo/data" "github.com/cuigh/auxo/net/web" "github.com/cuigh/swirl/biz" + "github.com/cuigh/swirl/docker" ) // ServiceHandler encapsulates service related handlers. @@ -70,6 +73,9 @@ func serviceFind(b biz.ServiceBiz) web.HandlerFunc { status := ctx.Query("status") == "true" service, raw, err := b.Find(name, status) if err != nil { + if docker.IsErrNotFound(err) { + return web.NewError(http.StatusNotFound, err.Error()) + } return err } return success(ctx, data.Map{"service": service, "raw": raw}) diff --git a/api/task.go b/api/task.go index 423cd15..e5cace5 100644 --- a/api/task.go +++ b/api/task.go @@ -1,9 +1,12 @@ package api import ( + "net/http" + "github.com/cuigh/auxo/data" "github.com/cuigh/auxo/net/web" "github.com/cuigh/swirl/biz" + "github.com/cuigh/swirl/docker" ) // TaskHandler encapsulates node related handlers. @@ -57,6 +60,9 @@ func taskFind(b biz.TaskBiz) web.HandlerFunc { id := ctx.Query("id") task, raw, err := b.Find(id) if err != nil { + if docker.IsErrNotFound(err) { + return web.NewError(http.StatusNotFound, err.Error()) + } return err } return success(ctx, data.Map{"task": task, "raw": raw}) diff --git a/docker/docker.go b/docker/docker.go index a88cafa..37c0735 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -40,6 +40,10 @@ func NewDocker() *Docker { return d } +func IsErrNotFound(err error) bool { + return client.IsErrNotFound(err) +} + func (d *Docker) call(fn func(c *client.Client) error) error { c, err := d.client() if err == nil { diff --git a/ui/src/api/ajax.ts b/ui/src/api/ajax.ts index 36bac4a..5cf7c90 100644 --- a/ui/src/api/ajax.ts +++ b/ui/src/api/ajax.ts @@ -71,6 +71,9 @@ class Ajax { case 403: router.replace("/403"); return true + case 404: + router.replace("/404"); + return true case 500: this.showError(error) }