tasks/controller/response.php

28 lines
454 B
PHP
Raw Normal View History

2015-06-30 12:39:19 +00:00
<?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);
}
}