Skip to content

Commit a5c19b5

Browse files
authored
chore: better error messages for file serving endpoint (#242)
Signed-off-by: kyteinsky <kyteinsky@gmail.com>
1 parent 76b2240 commit a5c19b5

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

lib/Controller/QueueController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ public function getFileContents(IRootFolder $rootFolder, int $fileId, string $us
7171
try {
7272
$file = $rootFolder->getUserFolder($userId)->getFirstNodeById($fileId);
7373
if (!$file || !$file instanceof \OCP\Files\File) {
74-
return new DataResponse([], Http::STATUS_NOT_FOUND);
74+
return new DataResponse(['error' => 'Node is not a file or could not be found.'], Http::STATUS_NOT_FOUND);
7575
}
7676

7777
$stream = $file->fopen('r');
7878
if (!$stream) {
79-
return new DataResponse([], Http::STATUS_NOT_FOUND);
79+
return new DataResponse(['error' => 'File could not be opened for reading.'], Http::STATUS_UNPROCESSABLE_ENTITY);
8080
}
8181

8282
return new Http\StreamResponse($stream);
8383
} catch (\Throwable $e) {
84-
// Avoid leaking filesystem details; keep behavior consistent with other failure paths.
85-
return new DataResponse([], Http::STATUS_NOT_FOUND);
84+
$this->logger->error('Unknown error trying to read a file for indexing: ' . $e->getMessage(), ['exception' => $e]);
85+
return new DataResponse(['error' => 'Unknown error occurred.'], Http::STATUS_INTERNAL_SERVER_ERROR);
8686
}
8787
}
8888

0 commit comments

Comments
 (0)