Finished Error handling across the API
Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
committed by
Julius Härtl
parent
2668f6b80c
commit
dd1d4246fe
@@ -28,40 +28,22 @@ use OCP\AppFramework\Http;
|
||||
|
||||
class ApiHelper {
|
||||
|
||||
public static function boardHasError($boardId, $boardService) {
|
||||
if (is_numeric($boardId) === false) {
|
||||
$error['message'] = 'board id must be a number';
|
||||
public static function entityHasError($entityId, $entityName, $service) {
|
||||
if (is_numeric($entityId) === false) {
|
||||
$error['message'] = $entityName . ' id must be a number';
|
||||
$error['status'] = HTTP::STATUS_BAD_REQUEST;
|
||||
return $error;
|
||||
}
|
||||
|
||||
$board = $boardService->find($boardId);
|
||||
$entity = $service->find($entityId);
|
||||
|
||||
if ($board === false || $board === null) {
|
||||
$error['message'] = 'board does not exist';
|
||||
if ($entity === false || $entity === null) {
|
||||
$error['message'] = $entityName . ' does not exist';
|
||||
$error['status'] = HTTP::STATUS_NOT_FOUND;
|
||||
return $error;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function stackHasError($stackId, $stackService) {
|
||||
if (is_numeric($stackId) === false) {
|
||||
$error['message'] = 'board id must be a number';
|
||||
$error['status'] = HTTP::STATUS_BAD_REQUEST;
|
||||
return $error;
|
||||
}
|
||||
|
||||
$stack = $stackService->find($stackId);
|
||||
|
||||
if ($stack === false || $stack === null) {
|
||||
$error['message'] = 'stack does not exist';
|
||||
$error['status'] = HTTP::STATUS_NOT_FOUND;
|
||||
return $error;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user