Skip to content

Commit

Permalink
Improved crossref error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
cgxeiji committed Sep 14, 2019
1 parent ded7e8a commit 5041a7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,19 @@ func query(search string) string {

ws, err := client.Query(search)
if err != nil {
if err == crossref.ErrZeroWorks ||
err == crossref.ErrEmptyQuery {
info.println("Nothing found...")
return ""
}

panic(err)
}

if len(ws) == 1 {
return ws[0].DOI
}

type work struct {
Title string
Short string
Expand All @@ -242,14 +252,6 @@ func query(search string) string {

works := []work{}

switch len(ws) {
case 0:
info.println("Nothing found...")
return ""
case 1:
return ws[0].DOI
}

for _, v := range ws {
works = append(works, work{
Title: v.Title,
Expand Down Expand Up @@ -306,7 +308,7 @@ func query(search string) string {
func fetchDOI(doi string) (*scholar.Entry, error) {
client := crossref.NewClient("Scholar", viper.GetString("GENERAL.mailto"))

w, err := client.Works(doi)
w, err := client.DOI(doi)
if err != nil {
return &scholar.Entry{}, err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ Add an entry to create this directory or run:
scholar config
to set the correct path of this library.
`)
to set the correct path of this library.`,
)
panic("not found: library path")
}

Expand Down

0 comments on commit 5041a7b

Please sign in to comment.