Improvements on API error, swagger and status code (#428)

* improvements on API error, swagger and status code

* missing validation

* removing typo

* fix if-within-if

* fix handle app delete
This commit is contained in:
Pedro Nasser
2016-12-13 19:18:52 -02:00
committed by GitHub
parent 34d6c6e101
commit 32de7d5361
13 changed files with 103 additions and 88 deletions

View File

@@ -25,14 +25,14 @@ func (s *Server) handleRouteUpdate(c *gin.Context) {
}
if wroute.Route == nil {
log.WithError(err).Error(models.ErrInvalidJSON)
log.Debug(models.ErrRoutesMissingNew)
c.JSON(http.StatusBadRequest, simpleError(models.ErrRoutesMissingNew))
return
}
if wroute.Route.Path != "" {
log.Debug(models.ErrRoutesPathImmutable)
c.JSON(http.StatusForbidden, simpleError(models.ErrRoutesPathImmutable))
c.JSON(http.StatusBadRequest, simpleError(models.ErrRoutesPathImmutable))
return
}
@@ -44,14 +44,19 @@ func (s *Server) handleRouteUpdate(c *gin.Context) {
Image: wroute.Route.Image,
})
if err != nil {
c.JSON(http.StatusInternalServerError, simpleError(models.ErrUsableImage))
log.WithError(err).Debug(models.ErrRoutesUpdate)
c.JSON(http.StatusBadRequest, simpleError(models.ErrUsableImage))
return
}
}
route, err := s.Datastore.UpdateRoute(ctx, wroute.Route)
if err != nil {
if err == models.ErrRoutesNotFound {
log.WithError(err).Debug(models.ErrRoutesUpdate)
c.JSON(http.StatusNotFound, simpleError(err))
return
} else if err != nil {
log.WithError(err).Error(models.ErrRoutesUpdate)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrRoutesUpdate))
return
}