abort messages with http error code
[sheet.git] / common.inc.plp
index 9b61d52b4416a9c75d1fa74157e758b43c35b4f1..77880495c2be77883e45d013279c0aa296ad9a9e 100644 (file)
@@ -20,6 +20,20 @@ sub Alert {
        say "<div class=error>$body</div>\n";
 }
 
+sub Abort {
+       my ($html, $code, $debug) = @_;
+       unless ($PLP::sentheaders) {
+               $header{Status} = $code || 500;
+       }
+       elsif ($Dev) {
+               ref $html eq 'ARRAY' or $html = [$html];
+               push @{$html}, "Also failed to set HTTP status <q>$code</q>"
+                       . " after output!";
+       }
+       Alert($html, $debug);
+       exit;
+}
+
 BEGIN {
        require Time::HiRes;
        our $Time = [Time::HiRes::gettimeofday()];