mirror of
https://github.com/veops/oneterm.git
synced 2025-10-30 02:21:51 +08:00
refactor(backend): authorization v2
This commit is contained in:
@@ -63,10 +63,14 @@ func (c *Controller) GetConfig(ctx *gin.Context) {
|
||||
|
||||
cfg, err := configService.GetConfig(ctx)
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
ctx.AbortWithError(http.StatusInternalServerError, &myErrors.ApiError{Code: myErrors.ErrInternal, Data: map[string]any{"err": err}})
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// Return default configuration if no config exists
|
||||
defaultCfg := model.GetDefaultConfig()
|
||||
ctx.JSON(http.StatusOK, NewHttpResponseWithData(defaultCfg))
|
||||
return
|
||||
}
|
||||
ctx.AbortWithError(http.StatusInternalServerError, &myErrors.ApiError{Code: myErrors.ErrInternal, Data: map[string]any{"err": err}})
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, NewHttpResponseWithData(cfg))
|
||||
|
||||
Reference in New Issue
Block a user