Skip to content

Commit

Permalink
feat(import): add import error message
Browse files Browse the repository at this point in the history
  • Loading branch information
indes committed Oct 29, 2019
1 parent 3bc3d2e commit 968b34f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 9 additions & 1 deletion bot/bot.go
Expand Up @@ -608,10 +608,18 @@ func makeHandle() {

url, _ := B.FileURLByID(m.Document.FileID)
opml, err := GetOPMLByURL(url)

if err != nil {
_, _ = B.Send(m.Chat, "如果需要导入订阅,请发送正确的OPML文件。")
if err.Error() == "fetch opml file error" {
_, _ = B.Send(m.Chat,
"下载 OPML 文件失败,请检查 bot 服务器能否正常连接至 telegram 服务器或过段时间再尝试导入。")

} else {
_, _ = B.Send(m.Chat, "如果需要导入订阅,请发送正确的 OPML 文件。")
}
return
}

message, _ := B.Send(m.Chat, "处理中,请稍后。")
outlines, _ := opml.GetFlattenOutlines()
var failImportList []Outline
Expand Down
10 changes: 7 additions & 3 deletions bot/opml.go
Expand Up @@ -3,6 +3,7 @@ package bot
import (
"crypto/tls"
"encoding/xml"
"errors"
"github.com/indes/flowerss-bot/model"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -81,15 +82,18 @@ func GetOPMLByURL(file_url string) (*OPML, error) {
Timeout: time.Second * 5,
}
resp, err := client.Get(file_url)

if err != nil {
return nil, err
return nil, errors.New("fetch opml file error")
}

body, _ := ioutil.ReadAll(resp.Body)
o, err := NewOPML(body)

if err != nil {
return nil, err
return nil, errors.New("parse opml file error")
}
return o, err
return o, nil
}

func (o OPML) GetFlattenOutlines() ([]Outline, error) {
Expand Down

0 comments on commit 968b34f

Please sign in to comment.