From ca4ea152e955344f758bea998b0d12106b01466d Mon Sep 17 00:00:00 2001
From: Sam <dxb@keybase.io>
Date: Sat, 10 Aug 2019 11:25:52 -0400
Subject: [PATCH] Add better error handling

---
 chat.go | 4 ++++
 team.go | 8 +++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/chat.go b/chat.go
index 30d7b2f..ae436a6 100644
--- a/chat.go
+++ b/chat.go
@@ -3,6 +3,7 @@ package keybase
 import (
 	"bufio"
 	"encoding/json"
+	"errors"
 	"os/exec"
 	"strings"
 	"time"
@@ -114,6 +115,9 @@ func chatAPIOut(keybasePath string, c ChatAPI) (ChatAPI, error) {
 	if err := json.Unmarshal(cmdOut, &r); err != nil {
 		return ChatAPI{}, err
 	}
+	if r.Error != nil {
+		return ChatAPI{}, errors.New(r.Error.Message)
+	}
 
 	return r, nil
 }
diff --git a/team.go b/team.go
index 519406c..9a47a8d 100644
--- a/team.go
+++ b/team.go
@@ -2,6 +2,7 @@ package keybase
 
 import (
 	"encoding/json"
+	"errors"
 	"fmt"
 	"os/exec"
 )
@@ -17,7 +18,12 @@ func teamAPIOut(keybasePath string, w TeamAPI) (TeamAPI, error) {
 	}
 
 	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
 }