mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-01-11 00:11:27 +00:00
fix: handle GitHub API error responses in GetXrayVersions (#3609)
GitHub API returns JSON object instead of array when encountering errors (e.g., rate limit exceeded). This causes JSON unmarshal error: 'cannot unmarshal object into Go value of type []service.Release' Add HTTP status code check to handle error responses gracefully and return user-friendly error messages instead of JSON parsing errors. Fixes issue where getXrayVersion fails with unmarshal error when GitHub API rate limit is exceeded.
This commit is contained in:
parent
c061337ce7
commit
c881d1015a
1 changed files with 12 additions and 0 deletions
|
|
@ -529,6 +529,18 @@ func (s *ServerService) GetXrayVersions() ([]string, error) {
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Check HTTP status code - GitHub API returns object instead of array on error
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||
var errorResponse struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
if json.Unmarshal(bodyBytes, &errorResponse) == nil && errorResponse.Message != "" {
|
||||
return nil, fmt.Errorf("GitHub API error: %s", errorResponse.Message)
|
||||
}
|
||||
return nil, fmt.Errorf("GitHub API returned status %d: %s", resp.StatusCode, resp.Status)
|
||||
}
|
||||
|
||||
buffer := bytes.NewBuffer(make([]byte, bufferSize))
|
||||
buffer.Reset()
|
||||
if _, err := buffer.ReadFrom(resp.Body); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue