mirror of
https://github.com/cuigh/swirl
synced 2024-12-27 22:32:49 +00:00
Jump to page 404 when resource is not found
This commit is contained in:
parent
b55b53aa4b
commit
308d3ddc05
@ -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})
|
||||
|
@ -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})
|
||||
|
@ -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})
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user