mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Add nice(r) error message on api server panic. Fix nil ptr derefs.
This commit is contained in:
parent
9cd9754693
commit
b95eef522b
@ -70,6 +70,13 @@ func (server *ApiServer) handleIndex(w http.ResponseWriter) {
|
||||
|
||||
// HTTP Handler interface
|
||||
func (server *ApiServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
defer func() {
|
||||
if x := recover(); x != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprint(w, "apiserver panic. Look in log for details.")
|
||||
log.Printf("ApiServer panic'd: %#v\n", x)
|
||||
}
|
||||
}()
|
||||
log.Printf("%s %s", req.Method, req.RequestURI)
|
||||
url, err := url.ParseRequestURI(req.RequestURI)
|
||||
if err != nil {
|
||||
|
@ -49,6 +49,9 @@ func (storage *ControllerRegistryStorage) List(*url.URL) (interface{}, error) {
|
||||
|
||||
func (storage *ControllerRegistryStorage) Get(id string) (interface{}, error) {
|
||||
controller, err := storage.registry.GetController(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
controller.Kind = "cluster#replicationController"
|
||||
return controller, err
|
||||
}
|
||||
|
@ -61,12 +61,18 @@ func GetServiceEnvironmentVariables(registry ServiceRegistry, machine string) ([
|
||||
|
||||
func (sr *ServiceRegistryStorage) List(*url.URL) (interface{}, error) {
|
||||
list, err := sr.registry.ListServices()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list.Kind = "cluster#serviceList"
|
||||
return list, err
|
||||
}
|
||||
|
||||
func (sr *ServiceRegistryStorage) Get(id string) (interface{}, error) {
|
||||
service, err := sr.registry.GetService(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
service.Kind = "cluster#service"
|
||||
return service, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user