SOS alert on ntg fail auth
This commit is contained in:
@@ -121,9 +121,6 @@ func (ntg NTGVision) searchJob(id int64) (io.ReadCloser, error) {
|
||||
defer resp.Body.Close()
|
||||
b, _ := ioutil.ReadAll(resp.Body)
|
||||
logtr.Debugf("fetch ntg job info %+v: %d: %s", request, resp.StatusCode, b)
|
||||
if resp.StatusCode > 400 && resp.StatusCode < 500 && resp.StatusCode != 404 && resp.StatusCode != 410 {
|
||||
return nil, ErrNoAuth
|
||||
}
|
||||
return io.NopCloser(bytes.NewReader(b)), nil
|
||||
}
|
||||
|
||||
@@ -173,15 +170,10 @@ func (ntg NTGVision) WithMock() NTGVision {
|
||||
|
||||
func (ntg NTGVision) SearchJob(id int64) (ntgVisionJobInfo, error) {
|
||||
rc, err := ntg.searcher.searchJob(id)
|
||||
if err == ErrNoAuth {
|
||||
if err := ntg.refreshAuth(); err != nil {
|
||||
return ntgVisionJobInfo{}, err
|
||||
}
|
||||
rc, err = ntg.searcher.searchJob(id)
|
||||
}
|
||||
if err != nil {
|
||||
return ntgVisionJobInfo{}, err
|
||||
}
|
||||
defer rc.Close()
|
||||
var result ntgVisionJobInfo
|
||||
err = json.NewDecoder(rc).Decode(&result)
|
||||
return result, err
|
||||
@@ -243,6 +235,14 @@ func (ntg NTGVision) search(states []config.State) (io.ReadCloser, error) {
|
||||
}
|
||||
|
||||
func (ntg NTGVision) refreshAuth() error {
|
||||
err := ntg.refreshAuth()
|
||||
if err != nil {
|
||||
logtr.SOSf("failed to refresh ntg auth: %v", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (ntg NTGVision) _refreshAuth() error {
|
||||
logtr.Infof("refreshing ntg auth...")
|
||||
b, _ := json.Marshal(map[string]string{
|
||||
"username": config.Get().Brokers.NTG.Username,
|
||||
|
||||
Reference in New Issue
Block a user