You could implement the test in firmware and request a stop print in that case. For repetier-firmware the server has in it's firmware this stop definition:
<response type="stopPrint">RequestStop:</response>
In marlin there is no such entry, but you can add one.
What this means is if firmware send in response a line containing
"RequestStop:"
it should stop the running print process.