expmail/Response.class.php
Kumi 730ad8c0e1 Move response to own class
Implement warning output
Implement warning when URL and string provided for HTML/plain
Turn allowempty to config key
Add option to prefer URL over string for HTML/plain
Add user agent to curl requests
Update OpenAPI
Bump version to 0.5
2020-09-05 09:12:28 +02:00

24 lines
654 B
PHP

<?php
class Response {
private $error;
private $warnings;
function handle_warning($warning) {
if (!$this->warnings) $this->warnings = array();
array_push($this->warnings, $warning);
}
function handle_exception($e) {
$this->error = $e->getMessage();
$this->respond();
}
function respond() {
header('Content-Type: application/json');
$response = array("status" => $this->error ? "error" : "success");
if ($this->error) $response["error"] = $this->error;
if ($this->warnings) $response["warnings"] = $this->warnings;
die(json_encode($response));
}
}