mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
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:
@@ -30,7 +30,7 @@ func (s *Server) handleAppUpdate(c *gin.Context) {
|
||||
|
||||
if wapp.App.Name != "" {
|
||||
log.Debug(models.ErrAppsNameImmutable)
|
||||
c.JSON(http.StatusForbidden, simpleError(models.ErrAppsNameImmutable))
|
||||
c.JSON(http.StatusBadRequest, simpleError(models.ErrAppsNameImmutable))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -38,25 +38,28 @@ func (s *Server) handleAppUpdate(c *gin.Context) {
|
||||
|
||||
err = s.FireAfterAppUpdate(ctx, wapp.App)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln(models.ErrAppsUpdate)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(err))
|
||||
log.WithError(err).Error(models.ErrAppsUpdate)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
|
||||
return
|
||||
}
|
||||
|
||||
app, err := s.Datastore.UpdateApp(ctx, wapp.App)
|
||||
if err != nil {
|
||||
if err == models.ErrAppsNotFound {
|
||||
log.WithError(err).Debug(models.ErrAppsUpdate)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsUpdate))
|
||||
c.JSON(http.StatusNotFound, simpleError(err))
|
||||
return
|
||||
} else if err != nil {
|
||||
log.WithError(err).Error(models.ErrAppsUpdate)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
|
||||
return
|
||||
}
|
||||
|
||||
err = s.FireAfterAppUpdate(ctx, wapp.App)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln(models.ErrAppsUpdate)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(err))
|
||||
log.WithError(err).Error(models.ErrAppsUpdate)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
|
||||
return
|
||||
}
|
||||
|
||||
// Nothing to update right now in apps
|
||||
c.JSON(http.StatusOK, appResponse{"App successfully updated", app})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user