In Dial-plan how to detect SIP response 4xx/5xx/6xx

I think you can’t get the SIP code responses in the dialplan, you have to use the DIALSTATUS variable.

See if this answers your question: How to check the result of the Dial application