move error

This commit is contained in:
Synox 2018-02-23 22:27:20 +01:00
parent 59aba28faf
commit f91c88cad3
3 changed files with 14 additions and 17 deletions

View File

@ -39,7 +39,9 @@ class ImapClient {
$this->mailbox->deleteMail($mailid);
$this->mailbox->expungeDeletedMails();
} else {
error(404, 'delete error: invalid username/mailid combination');
// TODO: use return/throw instead
@http_response_code(404);
die('delete error: invalid username/mailid combination');
}
}

View File

@ -26,20 +26,5 @@ $page->invoke($imapClient);
// delete after each request
$imapClient->delete_old_messages($config['delete_messages_older_than']);
/**
* print error and stop program.
* @param $status integer http status
* @param $text string error text
*/
function error($status, $text) {
@http_response_code($status);
@print("{\"error\": \"$text\"}");
die();
}
?>

View File

@ -25,6 +25,16 @@ abstract class Page {
header("location: ?$name@$domain");
}
/**
* print error and stop program.
* @param $status integer http status
* @param $text string error text
*/
function error($status, $text) {
@http_response_code($status);
die("{\"error\": \"$text\"}");
}
}
class RedirectToAddressPage extends Page {
@ -123,6 +133,6 @@ class DisplayEmailsPage extends Page {
class InvalidRequestPage extends Page {
function invoke(ImapClient $imapClient) {
error(400, "Bad Request");
$this->error(400, "Bad Request");
}
}