Instead of quit "contacts" use the following:
tell application "Contacts" to if it is running then quit
If you programmed your AppleScript to display its on error condition in a dialog, then you can also add the optional clause, giving up after n, where after n seconds, the dialog will automatically dismiss itself. See the display alert example in the AppleScript Language Guide.
Here is how I implement my own error handler:
set val to "A"
try
set val to val as number
on error errmsg number errnbr
my error_handler(errnbr, errmsg)
return
end try
return
on error_handler(nbr, msg)
return display alert "[ " & nbr & " ] " & msg as critical giving up after 10
end error_handler
If you didn't do the above, then AppleScript has stopped all processing and is waiting for you to click (return) that OK button. Nothing will happen until you do, so there is means to dismiss that dialog programmatically.