Catch transform errors

cache
Varun Patil 2022-10-07 23:46:08 -07:00
parent 3f6a31f2b5
commit 6d99ad01d7
3 changed files with 36 additions and 28 deletions

View File

@ -178,6 +178,7 @@ class ApiController extends Controller {
} }
// Run actual query // Run actual query
try {
$list = $this->timelineQuery->getDays( $list = $this->timelineQuery->getDays(
$folder, $folder,
$uid, $uid,
@ -195,6 +196,9 @@ class ApiController extends Controller {
} }
return new JSONResponse($list, Http::STATUS_OK); return new JSONResponse($list, Http::STATUS_OK);
} catch (\Exception $e) {
return new JSONResponse(["message" => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
}
} }
/** /**
@ -247,6 +251,7 @@ class ApiController extends Controller {
} }
// Run actual query // Run actual query
try {
$list = $this->timelineQuery->getDay( $list = $this->timelineQuery->getDay(
$folder, $folder,
$uid, $uid,
@ -256,6 +261,9 @@ class ApiController extends Controller {
$this->getTransformations(), $this->getTransformations(),
); );
return new JSONResponse($list, Http::STATUS_OK); return new JSONResponse($list, Http::STATUS_OK);
} catch (\Exception $e) {
return new JSONResponse(["message" => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
}
} }
/** /**

View File

@ -10,10 +10,10 @@ use OCP\Files\Folder;
trait TimelineQueryFaces { trait TimelineQueryFaces {
protected IDBConnection $connection; protected IDBConnection $connection;
public function transformFaceFilter(IQueryBuilder &$query, string $userId, string $faceName) { public function transformFaceFilter(IQueryBuilder &$query, string $userId, string $faceStr) {
// Get title and uid of face user // Get title and uid of face user
$faceNames = explode('/', $faceName); $faceNames = explode('/', $faceStr);
if (count($faceNames) !== 2) return; if (count($faceNames) !== 2) throw new \Exception("Invalid face query");
$faceUid = $faceNames[0]; $faceUid = $faceNames[0];
$faceName = $faceNames[1]; $faceName = $faceNames[1];
@ -23,7 +23,7 @@ trait TimelineQueryFaces {
->where($query->expr()->eq('user_id', $sq->createNamedParameter($faceUid))) ->where($query->expr()->eq('user_id', $sq->createNamedParameter($faceUid)))
->andWhere($query->expr()->eq('title', $sq->createNamedParameter($faceName))) ->andWhere($query->expr()->eq('title', $sq->createNamedParameter($faceName)))
->executeQuery()->fetchOne(); ->executeQuery()->fetchOne();
if (!$id) return; if (!$id) throw new \Exception("Unknown person: $faceStr");
// Join with cluster // Join with cluster
$query->innerJoin('m', 'recognize_face_detections', 'rfd', $query->expr()->andX( $query->innerJoin('m', 'recognize_face_detections', 'rfd', $query->expr()->andX(

View File

@ -22,7 +22,7 @@ trait TimelineQueryTags {
public function transformTagFilter(IQueryBuilder &$query, string $userId, string $tagName) { public function transformTagFilter(IQueryBuilder &$query, string $userId, string $tagName) {
$tagId = $this->getSystemTagId($query, $tagName); $tagId = $this->getSystemTagId($query, $tagName);
if ($tagId === FALSE) { if ($tagId === FALSE) {
$tagId = 0; // cannot abort here; that will show up everything in the response throw new \Exception("Tag $tagName not found");
} }
$query->innerJoin('m', 'systemtag_object_mapping', 'stom', $query->expr()->andX( $query->innerJoin('m', 'systemtag_object_mapping', 'stom', $query->expr()->andX(