tasks/controller/response.php
2015-06-30 14:42:58 +02:00

28 lines
No EOL
454 B
PHP

<?php
namespace OCA\Tasks\Controller;
use \Closure;
use \OCP\AppFramework\Http\JSONResponse;
trait Response {
protected function generateResponse (Closure $callback) {
try {
$message = [
'status' => 'success',
'data' => $callback(),
'message' => null
];
} catch(\Exception $e) {
$message = [
'status' => 'error',
'data' => null,
'message' => $e->getMessage()
];
}
return new JSONResponse($message);
}
}