fix(t234): log OCR result in diagnostics

This commit is contained in:
QiuSW
2026-07-29 11:32:10 +08:00
parent 38c090b3e7
commit 4cf2151d75
5 changed files with 109 additions and 11 deletions
@@ -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,