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
$list = $this->timelineQuery->getDays(
$folder,
$uid,
$recursive,
$archive,
$this->getTransformations(),
);
try {
$list = $this->timelineQuery->getDays(
$folder,
$uid,
$recursive,
$archive,
$this->getTransformations(),
);
// Preload some day responses
$this->preloadDays($list, $folder, $recursive, $archive);
// Preload some day responses
$this->preloadDays($list, $folder, $recursive, $archive);
// Add subfolder info if querying non-recursively
if (!$recursive) {
array_unshift($list, $this->getSubfoldersEntry($folder));
// Add subfolder info if querying non-recursively
if (!$recursive) {
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
$list = $this->timelineQuery->getDay(
$folder,
$uid,
$day_ids,
$recursive,
$archive,
$this->getTransformations(),
);
return new JSONResponse($list, Http::STATUS_OK);
try {
$list = $this->timelineQuery->getDay(
$folder,
$uid,
$day_ids,
$recursive,
$archive,
$this->getTransformations(),
);
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 {
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
$faceNames = explode('/', $faceName);
if (count($faceNames) !== 2) return;
$faceNames = explode('/', $faceStr);
if (count($faceNames) !== 2) throw new \Exception("Invalid face query");
$faceUid = $faceNames[0];
$faceName = $faceNames[1];
@ -23,7 +23,7 @@ trait TimelineQueryFaces {
->where($query->expr()->eq('user_id', $sq->createNamedParameter($faceUid)))
->andWhere($query->expr()->eq('title', $sq->createNamedParameter($faceName)))
->executeQuery()->fetchOne();
if (!$id) return;
if (!$id) throw new \Exception("Unknown person: $faceStr");
// Join with cluster
$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) {
$tagId = $this->getSystemTagId($query, $tagName);
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(