wiki fix
This commit is contained in:
@@ -59,6 +59,15 @@ func (r *wikiRepository) fetchList(tag string) ([]wikiPage, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if errorsRaw, ok := res["errors"].([]interface{}); ok && len(errorsRaw) > 0 {
|
||||||
|
if firstErr, ok := errorsRaw[0].(map[string]interface{}); ok {
|
||||||
|
if msg, ok := firstErr["message"].(string); ok {
|
||||||
|
return nil, fmt.Errorf("wiki error: %s", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("wiki returned an error")
|
||||||
|
}
|
||||||
|
|
||||||
data, ok := res["data"].(map[string]interface{})
|
data, ok := res["data"].(map[string]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("invalid response format")
|
return nil, fmt.Errorf("invalid response format")
|
||||||
@@ -95,8 +104,30 @@ func (r *wikiRepository) fetchContent(pageID interface{}) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := res["data"].(map[string]interface{})
|
if errorsRaw, ok := res["errors"].([]interface{}); ok && len(errorsRaw) > 0 {
|
||||||
pages := data["pages"].(map[string]interface{})
|
if firstErr, ok := errorsRaw[0].(map[string]interface{}); ok {
|
||||||
single := pages["single"].(map[string]interface{})
|
if msg, ok := firstErr["message"].(string); ok {
|
||||||
return single["content"].(string), nil
|
return "", fmt.Errorf("wiki error: %s", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("wiki returned an error")
|
||||||
|
}
|
||||||
|
|
||||||
|
data, ok := res["data"].(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return "", fmt.Errorf("invalid response format: missing data")
|
||||||
|
}
|
||||||
|
pages, ok := data["pages"].(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return "", fmt.Errorf("invalid response format: missing pages")
|
||||||
|
}
|
||||||
|
single, ok := pages["single"].(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return "", fmt.Errorf("page not found")
|
||||||
|
}
|
||||||
|
content, ok := single["content"].(string)
|
||||||
|
if !ok {
|
||||||
|
return "", fmt.Errorf("invalid response format: missing content")
|
||||||
|
}
|
||||||
|
return content, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user