feat(search-backend-module-pg): improve error handling

Co-authored-by: Emma Indal <emma.indahl@gmail.com>
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2022-06-28 11:26:37 +02:00
parent 34c97eb35b
commit 45e408ce79
@@ -15,6 +15,7 @@
*/
import { PluginDatabaseManager } from '@backstage/backend-common';
import { SearchEngine } from '@backstage/plugin-search-backend-node';
import { MissingIndexError } from '@backstage/plugin-search-backend-node';
import {
SearchQuery,
IndexableResultSet,
@@ -92,6 +93,12 @@ export class PgSearchEngine implements SearchEngine {
this.databaseStore.query(tx, pgQuery),
);
if (!rows.length) {
throw new MissingIndexError(
`Missing index for ${pgQuery.types}. This means there are no documents to search through.`,
);
}
// We requested one result more than the page size to know whether there is
// another page.
const { page } = decodePageCursor(query.pageCursor);