Skip to content

Commit 5f2c72c

Browse files
authored
Reduce 5xx spam (#496)
* Updating error frowarding from Transfer failures * Adding explicit call to psrpc.GetErrorCode(), only then overwriting it
1 parent 8c4e964 commit 5f2c72c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pkg/sip/protocol.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,16 @@ func handleReferNotify(cseq uint32, status int, reason string, referCseq uint32,
375375
Code: livekit.SIPStatusCode(status),
376376
Status: reason,
377377
}
378-
result = psrpc.NewErrorf(psrpc.Canceled, "call transfer failed: %w", st)
378+
// Converts SIP status to GRPC via SIPStatus.GRPCStatus(), then converts to psrpc via ErrorCodeFromGRPC()
379+
errorCode, _ := psrpc.GetErrorCode(st)
380+
if errorCode == psrpc.Internal || errorCode == psrpc.Unavailable {
381+
// Temporarily overwrite the code until we support a direct SIPStatus -> psrpc.ErrorCode conversion
382+
errorCode = psrpc.UpstreamServerError
383+
if status < 500 || status >= 600 { // Common 6xx codes: 603 Declined, 608 Rejected
384+
errorCode = psrpc.UpstreamClientError
385+
}
386+
}
387+
result = psrpc.NewErrorf(errorCode, "call transfer failed: %w", st)
379388
}
380389
select {
381390
case referDone <- result:
@@ -413,6 +422,10 @@ func sipStatusForErrorCode(code psrpc.ErrorCode) sip.StatusCode {
413422
return sip.StatusServiceUnavailable
414423
case psrpc.Unauthenticated:
415424
return sip.StatusUnauthorized
425+
case psrpc.UpstreamServerError:
426+
return sip.StatusBadGateway
427+
case psrpc.UpstreamClientError:
428+
return sip.StatusTemporarilyUnavailable
416429
default:
417430
return sip.StatusInternalServerError
418431
}

0 commit comments

Comments
 (0)