Add better error handling

This commit is contained in:
Sam
2019-08-10 11:25:52 -04:00
parent 86cde9fc83
commit ca4ea152e9
2 changed files with 11 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package keybase
import ( import (
"bufio" "bufio"
"encoding/json" "encoding/json"
"errors"
"os/exec" "os/exec"
"strings" "strings"
"time" "time"
@ -114,6 +115,9 @@ func chatAPIOut(keybasePath string, c ChatAPI) (ChatAPI, error) {
if err := json.Unmarshal(cmdOut, &r); err != nil { if err := json.Unmarshal(cmdOut, &r); err != nil {
return ChatAPI{}, err return ChatAPI{}, err
} }
if r.Error != nil {
return ChatAPI{}, errors.New(r.Error.Message)
}
return r, nil return r, nil
} }

View File

@ -2,6 +2,7 @@ package keybase
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"os/exec" "os/exec"
) )
@ -17,7 +18,12 @@ func teamAPIOut(keybasePath string, w TeamAPI) (TeamAPI, error) {
} }
var r TeamAPI var r TeamAPI
json.Unmarshal(cmdOut, &r) if err := json.Unmarshal(cmdOut, &r); err != nil {
return TeamAPI{}, err
}
if r.Error != nil {
return TeamAPI{}, errors.New(r.Error.Message)
}
return r, nil return r, nil
} }