Correctly handle validation errors vs. errors from the panel during installation
This commit is contained in:
parent
13fc464508
commit
7d7766e4cb
19
installer/errors.go
Normal file
19
installer/errors.go
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package installer
|
||||||
|
|
||||||
|
type validationError struct {
|
||||||
|
msg string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *validationError) Error() string {
|
||||||
|
return e.msg
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsValidationError(err error) bool {
|
||||||
|
_, ok := err.(*validationError)
|
||||||
|
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewValidationError(msg string) error {
|
||||||
|
return &validationError{msg: msg}
|
||||||
|
}
|
|
@ -22,11 +22,11 @@ type Installer struct {
|
||||||
// calling Execute().
|
// calling Execute().
|
||||||
func New(data []byte) (*Installer, error) {
|
func New(data []byte) (*Installer, error) {
|
||||||
if !govalidator.IsUUIDv4(getString(data, "uuid")) {
|
if !govalidator.IsUUIDv4(getString(data, "uuid")) {
|
||||||
return nil, errors.New("uuid provided was not in a valid format")
|
return nil, NewValidationError("uuid provided was not in a valid format")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !govalidator.IsUUIDv4(getString(data, "service", "egg")) {
|
if !govalidator.IsUUIDv4(getString(data, "service", "egg")) {
|
||||||
return nil, errors.New("service egg provided was not in a valid format")
|
return nil, NewValidationError("service egg provided was not in a valid format")
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &server.Server{
|
s := &server.Server{
|
||||||
|
@ -82,11 +82,6 @@ func New(data []byte) (*Installer, error) {
|
||||||
return nil, errors.New(rerr.String())
|
return nil, errors.New(rerr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
/*b, err := s.WriteConfigurationToDisk()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Destroy the temporary server instance.
|
// Destroy the temporary server instance.
|
||||||
s = nil
|
s = nil
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,14 @@ func postCreateServer(c *gin.Context) {
|
||||||
|
|
||||||
install, err := installer.New(buf.Bytes())
|
install, err := installer.New(buf.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
TrackedError(err).
|
if installer.IsValidationError(err) {
|
||||||
SetMessage("Failed to validate the data provided in the request.").
|
c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{
|
||||||
AbortWithStatus(http.StatusUnprocessableEntity, c)
|
"error": "The data provided in the request could not be validated.",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
TrackedError(err).AbortWithServerError(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user