mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Catch intermittent failure with HIBP module
This commit is contained in:
parent
97ca61ac97
commit
0db7e7c533
@ -75,23 +75,23 @@ func (widget *Widget) fetchForAccount(account string, since string) (*Status, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) parseResponseBody(account string, body []byte) (*Status, error) {
|
func (widget *Widget) parseResponseBody(account string, body []byte) (*Status, error) {
|
||||||
// If the body is empty then there's no breaches
|
breaches := []Breach{}
|
||||||
|
stat := NewStatus(account, breaches)
|
||||||
|
|
||||||
if len(body) == 0 {
|
if len(body) == 0 {
|
||||||
stat := NewStatus(account, []Breach{})
|
// If the body is empty then there's no breaches
|
||||||
return stat, nil
|
return stat, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Else we have breaches for this account
|
|
||||||
breaches := make([]Breach, 0)
|
|
||||||
|
|
||||||
jsonErr := json.Unmarshal(body, &breaches)
|
jsonErr := json.Unmarshal(body, &breaches)
|
||||||
if jsonErr != nil {
|
if jsonErr != nil {
|
||||||
return nil, jsonErr
|
return stat, jsonErr
|
||||||
}
|
}
|
||||||
|
|
||||||
breaches = widget.filterBreaches(breaches)
|
breaches = widget.filterBreaches(breaches)
|
||||||
|
stat.Breaches = breaches
|
||||||
|
|
||||||
return NewStatus(account, breaches), nil
|
return stat, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) filterBreaches(breaches []Breach) []Breach {
|
func (widget *Widget) filterBreaches(breaches []Breach) []Breach {
|
||||||
|
@ -24,5 +24,9 @@ func (stat *Status) HasBeenCompromised() bool {
|
|||||||
|
|
||||||
// Len returns the number of breaches found for the specified account
|
// Len returns the number of breaches found for the specified account
|
||||||
func (stat *Status) Len() int {
|
func (stat *Status) Len() int {
|
||||||
|
if stat == nil || stat.Breaches == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
return len(stat.Breaches)
|
return len(stat.Breaches)
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,6 @@ func Test_CenterText(t *testing.T) {
|
|||||||
Equal(t, " cat ", CenterText("cat", 9))
|
Equal(t, " cat ", CenterText("cat", 9))
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_HighlightableHelper(t *testing.T) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_RowPadding(t *testing.T) {
|
func Test_RowPadding(t *testing.T) {
|
||||||
Equal(t, "", RowPadding(0, 0))
|
Equal(t, "", RowPadding(0, 0))
|
||||||
Equal(t, "", RowPadding(5, 2))
|
Equal(t, "", RowPadding(5, 2))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user