Skip to content

Commit

Permalink
[warp] report error in change license
Browse files Browse the repository at this point in the history
Co-Authored-By: Alireza Ahmadi <[email protected]>
  • Loading branch information
MHSanaei and alireza0 committed Dec 3, 2024
1 parent 749a426 commit 4e0aca1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion web/service/warp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"time"
"x-ui/logger"
"x-ui/util/common"
)

type WarpService struct {
Expand Down Expand Up @@ -150,13 +151,23 @@ func (s *WarpService) SetWarpLicense(license string) (string, error) {
return "", err
}

var response map[string]interface{}
err = json.Unmarshal(buffer.Bytes(), &response)
if err != nil {
return "", err
}
if response["success"] == false {
errorArr, _ := response["errors"].([]interface{})
errorObj := errorArr[0].(map[string]interface{})
return "", common.NewError(errorObj["code"], errorObj["message"])
}

warpData["license_key"] = license
newWarpData, err := json.MarshalIndent(warpData, "", " ")
if err != nil {
return "", err
}
s.SettingService.SetWarp(string(newWarpData))
println(string(newWarpData))

return string(newWarpData), nil
}

0 comments on commit 4e0aca1

Please sign in to comment.