fix(t231): expose freight preflight errors
This commit is contained in:
@@ -294,13 +294,14 @@ func (service *FreightService) ensureSource(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
if err := preflight.EnsureAuthenticated(ctx); err != nil {
|
||||
code := freightSourceErrorCode(err)
|
||||
result := newError(
|
||||
ErrorKindUnavailable,
|
||||
freightSourceErrorCode(err),
|
||||
"freight source session is unavailable",
|
||||
code,
|
||||
freightPreflightMessage(code),
|
||||
err,
|
||||
)
|
||||
result.Retryable = true
|
||||
result.Retryable = code == "OCR_SERVICE_INVALID" || code == "ERP_UNAVAILABLE"
|
||||
return result
|
||||
}
|
||||
return nil
|
||||
@@ -709,11 +710,28 @@ func freightSourceErrorCode(err error) string {
|
||||
return "ERP_RESPONSE_INVALID"
|
||||
case errors.Is(err, domain.ErrFreightSourceOCRInvalid):
|
||||
return "OCR_SERVICE_INVALID"
|
||||
case errors.Is(err, domain.ErrFreightSourceLoginRejected):
|
||||
return "ERP_LOGIN_REJECTED"
|
||||
default:
|
||||
return "ERP_UNAVAILABLE"
|
||||
}
|
||||
}
|
||||
|
||||
func freightPreflightMessage(code string) string {
|
||||
switch code {
|
||||
case "ERP_NOT_CONFIGURED":
|
||||
return "ERP credentials are not configured"
|
||||
case "ERP_LOGIN_REJECTED":
|
||||
return "ERP login was rejected"
|
||||
case "ERP_RESPONSE_INVALID":
|
||||
return "ERP response is invalid"
|
||||
case "OCR_SERVICE_INVALID":
|
||||
return "OCR service is invalid"
|
||||
default:
|
||||
return "ERP is temporarily unavailable"
|
||||
}
|
||||
}
|
||||
|
||||
func validExternalID(value string) (string, bool) {
|
||||
value = strings.TrimSpace(value)
|
||||
number, err := strconv.ParseUint(value, 10, 64)
|
||||
|
||||
Reference in New Issue
Block a user