Prechádzať zdrojové kódy

Feature better 404s (#416)

* feature: CSS on actions

* feature: Less crashes when things are not found
James Read 1 rok pred
rodič
commit
1d9502d800
2 zmenil súbory, kde vykonal 13 pridanie a 3 odobranie
  1. 9 3
      internal/grpcapi/grpcApi.go
  2. 4 0
      webui.dev/js/marshaller.js

+ 9 - 3
internal/grpcapi/grpcApi.go

@@ -7,6 +7,8 @@ import (
 	log "github.com/sirupsen/logrus"
 	log "github.com/sirupsen/logrus"
 	"google.golang.org/genproto/googleapis/api/httpbody"
 	"google.golang.org/genproto/googleapis/api/httpbody"
 	"google.golang.org/grpc"
 	"google.golang.org/grpc"
+	"google.golang.org/grpc/codes"
+	"google.golang.org/grpc/status"
 
 
 	"errors"
 	"errors"
 	"net"
 	"net"
@@ -70,7 +72,7 @@ func (api *oliveTinAPI) StartAction(ctx ctx.Context, req *pb.StartActionRequest)
 	api.executor.MapActionIdToBindingLock.RUnlock()
 	api.executor.MapActionIdToBindingLock.RUnlock()
 
 
 	if pair == nil || pair.Action == nil {
 	if pair == nil || pair.Action == nil {
-		return nil, errors.New("Action not found")
+		return nil, status.Errorf(codes.NotFound, "Action not found.")
 	}
 	}
 
 
 	execReq := executor.ExecutionRequest{
 	execReq := executor.ExecutionRequest{
@@ -153,7 +155,7 @@ func (api *oliveTinAPI) StartActionByGetAndWait(ctx ctx.Context, req *pb.StartAc
 			LogEntry: internalLogEntryToPb(internalLogEntry),
 			LogEntry: internalLogEntryToPb(internalLogEntry),
 		}, nil
 		}, nil
 	} else {
 	} else {
-		return nil, errors.New("Execution not found!")
+		return nil, status.Errorf(codes.NotFound, "Execution not found.")
 	}
 	}
 }
 }
 
 
@@ -211,7 +213,11 @@ func (api *oliveTinAPI) ExecutionStatus(ctx ctx.Context, req *pb.ExecutionStatus
 		ile = getMostRecentExecutionStatusById(api, req.ActionId)
 		ile = getMostRecentExecutionStatusById(api, req.ActionId)
 	}
 	}
 
 
-	res.LogEntry = internalLogEntryToPb(ile)
+	if ile == nil {
+		return nil, status.Errorf(codes.NotFound, "Execution not found.")
+	} else {
+		res.LogEntry = internalLogEntryToPb(ile)
+	}
 
 
 	return res, nil
 	return res, nil
 }
 }

+ 4 - 0
webui.dev/js/marshaller.js

@@ -328,6 +328,10 @@ function marshalLink (item, fieldset) {
     btn.classList.add('error')
     btn.classList.add('error')
   }
   }
 
 
+  if (item.cssClass !== '') {
+    btn.classList.add(item.cssClass)
+  }
+
   fieldset.appendChild(btn)
   fieldset.appendChild(btn)
 }
 }