Add nice(r) error message on api server panic. Fix nil ptr derefs.

This commit is contained in:
Daniel Smith 2014-06-13 14:58:08 -07:00
parent 9cd9754693
commit b95eef522b
3 changed files with 16 additions and 0 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}