|
@@ -3,6 +3,7 @@ package discourse
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "net/http"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
@@ -24,14 +25,22 @@ func GetAbout(config APIConfig) (About, error) {
|
|
|
|
|
|
req, _ := newGetRequest(config, url)
|
|
|
client := getClient()
|
|
|
- response, _ := client.Do(req)
|
|
|
+ response, err := client.Do(req)
|
|
|
|
|
|
- var result *AboutResponse
|
|
|
- json.NewDecoder(response.Body).Decode(&result)
|
|
|
+ if err != nil {
|
|
|
+ return About{}, fmt.Errorf("Unable to connect to discourse server at %s -- %s", url, err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if response.StatusCode == http.StatusOK || response.StatusCode == http.StatusForbidden {
|
|
|
+ var result *AboutResponse
|
|
|
+ json.NewDecoder(response.Body).Decode(&result)
|
|
|
+
|
|
|
+ if result.ErrorType != "" {
|
|
|
+ return About{}, fmt.Errorf("Failed to get discourse version. Error: %s", strings.Join(result.Errors, "; "))
|
|
|
+ }
|
|
|
|
|
|
- if result.ErrorType != "" {
|
|
|
- return About{}, fmt.Errorf("Failed to get discourse version. Error: %s", strings.Join(result.Errors, "; "))
|
|
|
+ return result.About, nil
|
|
|
}
|
|
|
|
|
|
- return result.About, nil
|
|
|
+ return About{}, fmt.Errorf("Unexpected response from discourse server at %s -- %s", url, response.Status)
|
|
|
}
|