Add support for out of capacity error message
This commit is contained in:
@@ -2,10 +2,12 @@ package handlers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/play-with-docker/play-with-docker/provisioner"
|
||||||
"github.com/play-with-docker/play-with-docker/pwd"
|
"github.com/play-with-docker/play-with-docker/pwd"
|
||||||
"github.com/play-with-docker/play-with-docker/pwd/types"
|
"github.com/play-with-docker/play-with-docker/pwd/types"
|
||||||
)
|
)
|
||||||
@@ -25,6 +27,10 @@ func NewInstance(rw http.ResponseWriter, req *http.Request) {
|
|||||||
if pwd.SessionComplete(err) {
|
if pwd.SessionComplete(err) {
|
||||||
rw.WriteHeader(http.StatusConflict)
|
rw.WriteHeader(http.StatusConflict)
|
||||||
return
|
return
|
||||||
|
} else if provisioner.OutOfCapacity(err) {
|
||||||
|
rw.WriteHeader(http.StatusServiceUnavailable)
|
||||||
|
fmt.Fprintln(rw, `{"error": "out_of_capacity"}`)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
rw.WriteHeader(http.StatusInternalServerError)
|
rw.WriteHeader(http.StatusInternalServerError)
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
package provisioner
|
package provisioner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/play-with-docker/play-with-docker/pwd/types"
|
"github.com/play-with-docker/play-with-docker/pwd/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var OutOfCapacityError = errors.New("OutOfCapacity")
|
||||||
|
|
||||||
|
func OutOfCapacity(e error) bool {
|
||||||
|
return e == OutOfCapacityError
|
||||||
|
}
|
||||||
|
|
||||||
type InstanceProvisionerApi interface {
|
type InstanceProvisionerApi interface {
|
||||||
InstanceNew(session *types.Session, conf types.InstanceConfig) (*types.Instance, error)
|
InstanceNew(session *types.Session, conf types.InstanceConfig) (*types.Instance, error)
|
||||||
InstanceDelete(session *types.Session, instance *types.Instance) error
|
InstanceDelete(session *types.Session, instance *types.Instance) error
|
||||||
|
|||||||
@@ -127,6 +127,8 @@
|
|||||||
}, function(response) {
|
}, function(response) {
|
||||||
if (response.status == 409) {
|
if (response.status == 409) {
|
||||||
$scope.showAlert('Max instances reached', 'Maximum number of instances reached')
|
$scope.showAlert('Max instances reached', 'Maximum number of instances reached')
|
||||||
|
} else if (response.status == 503 && response.data.error == 'out_of_capacity') {
|
||||||
|
$scope.showAlert('Out Of Capacity', 'We are really sorry. But we are currently out of capacity and cannot create new instances. Please try again later.')
|
||||||
}
|
}
|
||||||
}).finally(function() {
|
}).finally(function() {
|
||||||
updateNewInstanceBtnState(false);
|
updateNewInstanceBtnState(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user