Incorrect dialstatus getting captured

what is the right code to capture dialstatus when I forward and incoming call to particular agent, below is the code which I am using.

same => n,Dial(SIP/${serverip}/${agentid},10,rg)
same => n,Goto(s-${DIALSTATUS},1)

exten => s-CONGESTION,1,MYSQL(Connect connid easy easy@pb asterisk)
exten => s-CONGESTION,n,MYSQL(Query r ${connid} UPDATE callers set calltoagentstatus=‘CONGESTION’ where callid=’${UNIQUEID}’)
exten => s-CONGESTION,n,MYSQL(Disconnect ${connid})
exten => s-CONGESTION,n,Goto(srqbooking,s,1)

exten => s-NOANSWER,1,MYSQL(Connect connid easy easy@pb asterisk)
exten => s-NOANSWER,n,MYSQL(Query r ${connid} UPDATE callers set calltoagentstatus=‘NOANSWER’ where callid=’${UNIQUEID}’)
exten => s-NOANSWER,n,MYSQL(Disconnect ${connid})
exten => s-NOANSWER,n,Goto(srqbooking,s,1)

exten => s-CHANUNAVAIL,1,MYSQL(Connect connid easy easy@pb asterisk)
exten => s-CHANUNAVAIL,n,MYSQL(Query r ${connid} UPDATE callers set calltoagentstatus=‘CHANUNAVAIL’ where callid=’${UNIQUEID}’)
exten => s-CHANUNAVAIL,n,MYSQL(Disconnect ${connid})
exten => s-CHANUNAVAIL,n,Goto(srqbooking,s,1)

exten => s-BUSY,1,MYSQL(Connect connid easy easy@pb asterisk)
exten => s-BUSY,n,MYSQL(Query r ${connid} UPDATE callers set calltoagentstatus=‘BUSY’ where callid=’${UNIQUEID}’)
exten => s-BUSY,n,MYSQL(Disconnect ${connid})
exten => s-BUSY,n,Goto(srqbooking,s,1)

exten => s-ANSWER,1,MYSQL(Connect connid easy easy@pb asterisk)
exten => s-ANSWER,n,MYSQL(Query r ${connid} UPDATE callers set calltoagentstatus=‘Answered’ where callid=’${UNIQUEID}’)
exten => s-ANSWER,n,MYSQL(Disconnect ${connid})
exten => s-ANSWER,n,Hangup()

but so many times after dialing the output is coming on cli is
Spawn extension (srcbooking, s, 16) exited non-zero on ‘DAHDI/i3/9812167930-19c’

and when i see in cdr i got talk time as well

The caller hung up first. You would have to use an h extension to run any dialplan in that case.

you mean in all these cases where I got Spawn extension (srcbooking, s, 16) exited non-zero on ‘DAHDI/i3/9812167930-19c’ here customer disconnected the calls??

can i get the dialstatus before hangup the call?

I need a system where i will forward the incoming call to an agent and will take action on the basis of whether agent answer the call/rejected,was busy

Dial does not return until the call has completed or failed. It does more than just the dialling; it also supervises the connected phase.

If you want things done between answer and call bridging, you need to use the subroutine or GoTo options on Dial, or handle the AMI events.

Thanks a lot David I have got something I m getting below

Spawn extension (phones, 3056461, 3) exited non-zero on ‘SIP/serverAWS1-00000016’

when Customer end the connected call