Finished Error handling across the API

Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
Ryan Fletcher
2018-07-13 19:07:08 -04:00
committed by Julius Härtl
parent 2668f6b80c
commit dd1d4246fe
5 changed files with 34 additions and 44 deletions

View File

@@ -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;
}
}
}