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,23 +178,27 @@ class ApiController extends Controller {
} }
// Run actual query // Run actual query
$list = $this->timelineQuery->getDays( try {
$folder, $list = $this->timelineQuery->getDays(
$uid, $folder,
$recursive, $uid,
$archive, $recursive,
$this->getTransformations(), $archive,
); $this->getTransformations(),
);
// Preload some day responses // Preload some day responses
$this->preloadDays($list, $folder, $recursive, $archive); $this->preloadDays($list, $folder, $recursive, $archive);
// Add subfolder info if querying non-recursively // Add subfolder info if querying non-recursively
if (!$recursive) { if (!$recursive) {
array_unshift($list, $this->getSubfoldersEntry($folder)); array_unshift($list, $this->getSubfoldersEntry($folder));
}
return new JSONResponse($list, Http::STATUS_OK);
} catch (\Exception $e) {
return new JSONResponse(["message" => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
} }
return new JSONResponse($list, Http::STATUS_OK);
} }
/** /**
@ -247,15 +251,19 @@ class ApiController extends Controller {
} }
// Run actual query // Run actual query
$list = $this->timelineQuery->getDay( try {
$folder, $list = $this->timelineQuery->getDay(
$uid, $folder,
$day_ids, $uid,
$recursive, $day_ids,
$archive, $recursive,
$this->getTransformations(), $archive,
); $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(