Jump to page 404 when resource is not found

This commit is contained in:
cuigh 2021-12-24 11:50:21 +08:00
parent b55b53aa4b
commit 308d3ddc05
5 changed files with 24 additions and 0 deletions

View File

@ -2,11 +2,13 @@ package api
import ( import (
"io" "io"
"net/http"
"github.com/cuigh/auxo/data" "github.com/cuigh/auxo/data"
"github.com/cuigh/auxo/log" "github.com/cuigh/auxo/log"
"github.com/cuigh/auxo/net/web" "github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz" "github.com/cuigh/swirl/biz"
"github.com/cuigh/swirl/docker"
"github.com/gobwas/ws" "github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil" "github.com/gobwas/ws/wsutil"
) )
@ -70,6 +72,9 @@ func containerFind(b biz.ContainerBiz) web.HandlerFunc {
id := ctx.Query("id") id := ctx.Query("id")
container, raw, err := b.Find(node, id) container, raw, err := b.Find(node, id)
if err != nil { if err != nil {
if docker.IsErrNotFound(err) {
return web.NewError(http.StatusNotFound, err.Error())
}
return err return err
} }
return success(ctx, data.Map{"container": container, "raw": raw}) return success(ctx, data.Map{"container": container, "raw": raw})

View File

@ -1,9 +1,12 @@
package api package api
import ( import (
"net/http"
"github.com/cuigh/auxo/data" "github.com/cuigh/auxo/data"
"github.com/cuigh/auxo/net/web" "github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz" "github.com/cuigh/swirl/biz"
"github.com/cuigh/swirl/docker"
) )
// ServiceHandler encapsulates service related handlers. // ServiceHandler encapsulates service related handlers.
@ -70,6 +73,9 @@ func serviceFind(b biz.ServiceBiz) web.HandlerFunc {
status := ctx.Query("status") == "true" status := ctx.Query("status") == "true"
service, raw, err := b.Find(name, status) service, raw, err := b.Find(name, status)
if err != nil { if err != nil {
if docker.IsErrNotFound(err) {
return web.NewError(http.StatusNotFound, err.Error())
}
return err return err
} }
return success(ctx, data.Map{"service": service, "raw": raw}) return success(ctx, data.Map{"service": service, "raw": raw})

View File

@ -1,9 +1,12 @@
package api package api
import ( import (
"net/http"
"github.com/cuigh/auxo/data" "github.com/cuigh/auxo/data"
"github.com/cuigh/auxo/net/web" "github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz" "github.com/cuigh/swirl/biz"
"github.com/cuigh/swirl/docker"
) )
// TaskHandler encapsulates node related handlers. // TaskHandler encapsulates node related handlers.
@ -57,6 +60,9 @@ func taskFind(b biz.TaskBiz) web.HandlerFunc {
id := ctx.Query("id") id := ctx.Query("id")
task, raw, err := b.Find(id) task, raw, err := b.Find(id)
if err != nil { if err != nil {
if docker.IsErrNotFound(err) {
return web.NewError(http.StatusNotFound, err.Error())
}
return err return err
} }
return success(ctx, data.Map{"task": task, "raw": raw}) return success(ctx, data.Map{"task": task, "raw": raw})

View File

@ -40,6 +40,10 @@ func NewDocker() *Docker {
return d return d
} }
func IsErrNotFound(err error) bool {
return client.IsErrNotFound(err)
}
func (d *Docker) call(fn func(c *client.Client) error) error { func (d *Docker) call(fn func(c *client.Client) error) error {
c, err := d.client() c, err := d.client()
if err == nil { if err == nil {

View File

@ -71,6 +71,9 @@ class Ajax {
case 403: case 403:
router.replace("/403"); router.replace("/403");
return true return true
case 404:
router.replace("/404");
return true
case 500: case 500:
this.showError(error) this.showError(error)
} }