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:
@@ -36,24 +36,28 @@ func (s *Server) handleAppCreate(c *gin.Context) {
|
||||
|
||||
err = s.FireBeforeAppCreate(ctx, wapp.App)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln(models.ErrAppsCreate)
|
||||
log.WithError(err).Error(models.ErrAppsCreate)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(err))
|
||||
return
|
||||
}
|
||||
|
||||
app, err := s.Datastore.InsertApp(ctx, wapp.App)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln(models.ErrAppsCreate)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(err))
|
||||
if err == models.ErrAppsAlreadyExists {
|
||||
log.WithError(err).Debug(models.ErrAppsCreate)
|
||||
c.JSON(http.StatusConflict, simpleError(err))
|
||||
return
|
||||
} else if err != nil {
|
||||
log.WithError(err).Error(models.ErrAppsCreate)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
|
||||
return
|
||||
}
|
||||
|
||||
err = s.FireAfterAppCreate(ctx, wapp.App)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln(models.ErrAppsCreate)
|
||||
log.WithError(err).Error(models.ErrAppsCreate)
|
||||
c.JSON(http.StatusInternalServerError, simpleError(err))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, appResponse{"App successfully created", app})
|
||||
c.JSON(http.StatusOK, appResponse{"App successfully created", app})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user