Added exception handling to StackApiController->create()
Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
committed by
Julius Härtl
parent
656e8efa43
commit
8771e35f11
@@ -84,8 +84,8 @@ return [
|
|||||||
['name' => 'board_api#undo_delete', 'url' => '/api/v1.0/board/{id}/undo_delete', 'verb' => 'POST'],
|
['name' => 'board_api#undo_delete', 'url' => '/api/v1.0/board/{id}/undo_delete', 'verb' => 'POST'],
|
||||||
|
|
||||||
['name' => 'stack_api#index', 'url' => '/api/v1.0/board/{boardId}/stacks', 'verb' => 'GET'],
|
['name' => 'stack_api#index', 'url' => '/api/v1.0/board/{boardId}/stacks', 'verb' => 'GET'],
|
||||||
['name' => 'stack_api#create', 'url' => '/api/v1.0/board/{boardId}/stack', 'verb' => 'POST'],
|
['name' => 'stack_api#create', 'url' => '/api/v1.0/board/{boardId}/stacks', 'verb' => 'POST'],
|
||||||
['name' => 'stack_api#delete', 'url' => '/api/v1.0/board/{boardId}/stack/{id}', 'verb' => 'DELETE'],
|
['name' => 'stack_api#delete', 'url' => '/api/v1.0/board/{boardId}/stacks/{id}', 'verb' => 'DELETE'],
|
||||||
|
|
||||||
['name' => 'board_api#preflighted_cors', 'url' => '/api/v1.0/{path}',
|
['name' => 'board_api#preflighted_cors', 'url' => '/api/v1.0/{path}',
|
||||||
'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']],
|
'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']],
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use OCP\AppFramework\Http;
|
|||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
|
||||||
|
use OCA\Deck\StatusException;
|
||||||
use OCA\Deck\Service\StackService;
|
use OCA\Deck\Service\StackService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,7 +60,6 @@ class StackApiController extends ApiController {
|
|||||||
*/
|
*/
|
||||||
public function index($boardId) {
|
public function index($boardId) {
|
||||||
$stacks = $this->service->findAll($boardId);
|
$stacks = $this->service->findAll($boardId);
|
||||||
|
|
||||||
return new DataResponse($stacks);
|
return new DataResponse($stacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,19 +73,17 @@ class StackApiController extends ApiController {
|
|||||||
*
|
*
|
||||||
* Create a stack with the specified title and order.
|
* Create a stack with the specified title and order.
|
||||||
*/
|
*/
|
||||||
public function create($boardId, $title, $order) {
|
public function create($boardId, $title, $order) {
|
||||||
$errorMessage['params']['boardId'] = $boardId;
|
|
||||||
$errorMessage['params']['title'] = $title;
|
try {
|
||||||
$errorMessage['params']['order'] = $order;
|
// this throws a StatusException that needs to be caught and handled
|
||||||
|
$stack = $this->service->create($title, $boardId, $order);
|
||||||
|
} catch (StatusException $e) {
|
||||||
|
$errorMessage['error'] = $e->getMessage();
|
||||||
|
return new DataResponse($errorMessage, Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
// try {
|
return new DataResponse($stack, HTTP::STATUS_OK);
|
||||||
// // this throws a StatusException that needs to be caught and handled
|
|
||||||
// $stack = $this->service->create($title, $boardId, $order);
|
|
||||||
// } catch (StatusException $e) {
|
|
||||||
// return new DataResponse(null, Http::STATUS_OK);
|
|
||||||
// }
|
|
||||||
|
|
||||||
return new DataResponse($errorMessage, HTTP::STATUS_NOT_IMPLEMENTED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user