diff --git a/handlers/bootstrap.go b/handlers/bootstrap.go index fa506b4..1f890d5 100644 --- a/handlers/bootstrap.go +++ b/handlers/bootstrap.go @@ -57,6 +57,12 @@ func Register() { corsRouter.HandleFunc("/sessions/{sessionId}/instances/{instanceName}", DeleteInstance).Methods("DELETE") corsRouter.HandleFunc("/sessions/{sessionId}/instances/{instanceName}/exec", Exec).Methods("POST") + r.HandleFunc("/ooc", func(rw http.ResponseWriter, r *http.Request) { + http.ServeFile(rw, r, "./www/ooc.html") + }).Methods("GET") + r.HandleFunc("/503", func(rw http.ResponseWriter, r *http.Request) { + http.ServeFile(rw, r, "./www/503.html") + }).Methods("GET") r.HandleFunc("/p/{sessionId}", Home).Methods("GET") r.PathPrefix("/assets").Handler(http.FileServer(http.Dir("./www"))) r.HandleFunc("/robots.txt", func(rw http.ResponseWriter, r *http.Request) { diff --git a/handlers/new_session.go b/handlers/new_session.go index d57e0c9..16bad1f 100644 --- a/handlers/new_session.go +++ b/handlers/new_session.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/play-with-docker/play-with-docker/config" + "github.com/play-with-docker/play-with-docker/provisioner" "github.com/play-with-docker/play-with-docker/recaptcha" ) @@ -46,7 +47,13 @@ func NewSession(rw http.ResponseWriter, req *http.Request) { duration := config.GetDuration(reqDur) s, err := core.SessionNew(duration, stack, stackName, imageName) if err != nil { + if provisioner.OutOfCapacity(err) { + http.Redirect(rw, req, "/ooc", http.StatusFound) + return + } log.Println(err) + http.Redirect(rw, req, "/500", http.StatusInternalServerError) + return //TODO: Return some error code } else { hostname := req.Host diff --git a/www/503.html b/www/503.html new file mode 100644 index 0000000..44ea8d1 --- /dev/null +++ b/www/503.html @@ -0,0 +1,33 @@ + + + + Docker Playground + + + + + + +
+ An error has occured. If you have some time, please report it. Thanks! +
+ + + + + + + + + + diff --git a/www/ooc.html b/www/ooc.html new file mode 100644 index 0000000..eb5dd9f --- /dev/null +++ b/www/ooc.html @@ -0,0 +1,33 @@ + + + + Docker Playground + + + + + + +
+ We are really sorry but we are out of capacity and cannot create your session at the moment. Please try again later. +
+ + + + + + + + + +