report definite Agent pre-origin failures to release occupancy
This commit is contained in:
@@ -46,6 +46,18 @@ func NativeCallPhase(err error) string {
|
||||
return "unclassified"
|
||||
}
|
||||
|
||||
// NativeCallNeverSubmitted is true only when the error occurred before any
|
||||
// ARI originate request could have been sent. After submission, even a local
|
||||
// error or successful cleanup does not prove the carrier never received SIP.
|
||||
func NativeCallNeverSubmitted(err error) bool {
|
||||
switch NativeCallPhase(err) {
|
||||
case "validate", "ari_open", "rtp_listen", "subscribe":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// NativeCallHTTPStatus extracts a numeric ARI HTTP status without retaining
|
||||
// a provider response body, credential or request URL in diagnostic logs.
|
||||
func NativeCallHTTPStatus(err error) int {
|
||||
|
||||
@@ -101,6 +101,19 @@ type nativeHTTPStatusError struct{ code int }
|
||||
|
||||
func (e nativeHTTPStatusError) Error() string { return "private ARI response" }
|
||||
func (e nativeHTTPStatusError) Code() int { return e.code }
|
||||
func TestOnlyPreSubmitNativeFailureCanBeConfirmedNeverDialed(t *testing.T) {
|
||||
for _, phase := range []string{"validate", "ari_open", "rtp_listen", "subscribe"} {
|
||||
if !NativeCallNeverSubmitted(errors.Join(&NativeCallFailure{Phase: phase, Cause: errors.New("failed")}, errors.New("cleanup"))) {
|
||||
t.Fatalf("%s cannot have created an outbound call", phase)
|
||||
}
|
||||
}
|
||||
for _, phase := range []string{"originate", "answer_wait", "bridge_create", "external_media_create", "unclassified"} {
|
||||
if NativeCallNeverSubmitted(&NativeCallFailure{Phase: phase, Cause: errors.New("unknown")}) {
|
||||
t.Fatalf("%s might have originated", phase)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeCallFailureReportsStageAndHTTPStatusWithoutResponseBody(t *testing.T) {
|
||||
cause := fmt.Errorf("request failed: %w", nativeHTTPStatusError{code: 404})
|
||||
err := errors.Join(&NativeCallFailure{Phase: "originate", Cause: cause}, errors.New("cleanup failed"))
|
||||
|
||||
Reference in New Issue
Block a user