Browse Source

fix: handle inbounds interaction errors (#3009)

eliminates messages like: “Inbound created successfully (Port 100 is already busy)”.
Shishkevich D. 3 weeks ago
parent
commit
c988d55256
1 changed files with 12 additions and 0 deletions
  1. 12 0
      web/controller/inbound.go

+ 12 - 0
web/controller/inbound.go

@@ -104,6 +104,10 @@ func (a *InboundController) addInbound(c *gin.Context) {
 
 
 	needRestart := false
 	needRestart := false
 	inbound, needRestart, err = a.inboundService.AddInbound(inbound)
 	inbound, needRestart, err = a.inboundService.AddInbound(inbound)
+	if err != nil {
+		jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
+		return
+	}
 	jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundCreateSuccess"), inbound, err)
 	jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundCreateSuccess"), inbound, err)
 	if err == nil && needRestart {
 	if err == nil && needRestart {
 		a.xrayService.SetToNeedRestart()
 		a.xrayService.SetToNeedRestart()
@@ -118,6 +122,10 @@ func (a *InboundController) delInbound(c *gin.Context) {
 	}
 	}
 	needRestart := true
 	needRestart := true
 	needRestart, err = a.inboundService.DelInbound(id)
 	needRestart, err = a.inboundService.DelInbound(id)
+	if err != nil {
+		jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
+		return
+	}
 	jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundDeleteSuccess"), id, err)
 	jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundDeleteSuccess"), id, err)
 	if err == nil && needRestart {
 	if err == nil && needRestart {
 		a.xrayService.SetToNeedRestart()
 		a.xrayService.SetToNeedRestart()
@@ -140,6 +148,10 @@ func (a *InboundController) updateInbound(c *gin.Context) {
 	}
 	}
 	needRestart := true
 	needRestart := true
 	inbound, needRestart, err = a.inboundService.UpdateInbound(inbound)
 	inbound, needRestart, err = a.inboundService.UpdateInbound(inbound)
+	if err != nil {
+		jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
+		return
+	}
 	jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), inbound, err)
 	jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), inbound, err)
 	if err == nil && needRestart {
 	if err == nil && needRestart {
 		a.xrayService.SetToNeedRestart()
 		a.xrayService.SetToNeedRestart()