Files
hardlink/internal/paymentsvc/diagnostics.go
T

39 lines
935 B
Go

package paymentsvc
import (
"context"
"encoding/json"
"errors"
"io"
"net"
)
// SafeErrorCategory describes a failure without exposing URLs, payloads or credentials.
// It is diagnostic only and must not determine financial outcomes or retry eligibility.
func SafeErrorCategory(err error) string {
if err == nil {
return "unresolved_result"
}
switch {
case errors.Is(err, context.DeadlineExceeded):
return "timeout"
case errors.Is(err, context.Canceled):
return "cancelled"
case errors.Is(err, io.EOF), errors.Is(err, io.ErrUnexpectedEOF):
return "response_lost"
}
var networkError net.Error
if errors.As(err, &networkError) {
if networkError.Timeout() {
return "timeout"
}
return "connection_failure"
}
var syntaxError *json.SyntaxError
var typeError *json.UnmarshalTypeError
if errors.As(err, &syntaxError) || errors.As(err, &typeError) {
return "invalid_response"
}
return "provider_error"
}