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:
@@ -17,8 +17,8 @@ func (s *Server) handleAppDelete(c *gin.Context) {
|
||||
|
||||
routes, err := s.Datastore.GetRoutesByApp(ctx, app.Name, &models.RouteFilter{})
|
||||
if err != nil {
|
||||
log.WithError(err).Debug(models.ErrAppsRemoving)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsRemoving))
|
||||
log.WithError(err).Error(models.ErrAppsRemoving)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -30,25 +30,26 @@ func (s *Server) handleAppDelete(c *gin.Context) {
|
||||
|
||||
err = s.FireBeforeAppDelete(ctx, app)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln(models.ErrAppsRemoving)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(err))
|
||||
log.WithError(err).Error(models.ErrAppsRemoving)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.Datastore.RemoveApp(ctx, app.Name); err != nil {
|
||||
err = s.Datastore.RemoveApp(ctx, app.Name)
|
||||
if err == models.ErrAppsNotFound {
|
||||
log.WithError(err).Debug(models.ErrAppsRemoving)
|
||||
if err == models.ErrAppsNotFound {
|
||||
c.JSON(http.StatusNotFound, simpleError(models.ErrAppsNotFound))
|
||||
} else {
|
||||
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsRemoving))
|
||||
}
|
||||
c.JSON(http.StatusNotFound, simpleError(err))
|
||||
return
|
||||
} else if err != nil {
|
||||
log.WithError(err).Error(models.ErrAppsRemoving)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
|
||||
return
|
||||
}
|
||||
|
||||
err = s.FireAfterAppDelete(ctx, app)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln(models.ErrAppsRemoving)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(err))
|
||||
log.WithError(err).Error(models.ErrAppsRemoving)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user