fix(t234): log OCR result in diagnostics
This commit is contained in:
@@ -154,9 +154,16 @@ func (manager *SessionManager) EnsureAuthenticated(ctx context.Context) error {
|
||||
return domain.ErrFreightSourceProtocol
|
||||
}
|
||||
code, err := manager.recognizer.Recognize(ctx, image.Content, image.ContentType)
|
||||
if err != nil || !validCaptchaCode(code) {
|
||||
if err != nil {
|
||||
manager.logOCRResultFailed()
|
||||
return domain.ErrFreightSourceOCRInvalid
|
||||
}
|
||||
code = strings.TrimSpace(code)
|
||||
if !validCaptchaCode(code) {
|
||||
manager.logOCRResultInvalid()
|
||||
return domain.ErrFreightSourceOCRInvalid
|
||||
}
|
||||
manager.logOCRResult(code)
|
||||
_, err = manager.Login(ctx, status.CaptchaTicket, code)
|
||||
if errors.Is(err, ErrLoginRejected) {
|
||||
return domain.ErrFreightSourceLoginRejected
|
||||
@@ -479,6 +486,30 @@ func (manager *SessionManager) logERPTransportFailure(request *http.Request) {
|
||||
)
|
||||
}
|
||||
|
||||
func (manager *SessionManager) logOCRResult(value string) {
|
||||
if !manager.diagnosticsOn {
|
||||
return
|
||||
}
|
||||
manager.diagnosticLog(
|
||||
"erp_ocr_result value=" + strconv.Quote(value) +
|
||||
" length=" + strconv.Itoa(len(value)),
|
||||
)
|
||||
}
|
||||
|
||||
func (manager *SessionManager) logOCRResultInvalid() {
|
||||
if !manager.diagnosticsOn {
|
||||
return
|
||||
}
|
||||
manager.diagnosticLog("erp_ocr_result class=invalid")
|
||||
}
|
||||
|
||||
func (manager *SessionManager) logOCRResultFailed() {
|
||||
if !manager.diagnosticsOn {
|
||||
return
|
||||
}
|
||||
manager.diagnosticLog("erp_ocr_result class=failed")
|
||||
}
|
||||
|
||||
func (manager *SessionManager) logERPResponsePreview(
|
||||
request *http.Request,
|
||||
response *http.Response,
|
||||
|
||||
Reference in New Issue
Block a user