Handle errors in collators and decorators and log them.

Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
Oliver Sand
2021-06-21 14:09:04 +02:00
parent 14d43713c9
commit 9c8ea7e24e
2 changed files with 29 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-search-backend-node': patch
---
Handle errors in collators and decorators and log them.
@@ -14,7 +14,11 @@
* limitations under the License.
*/
import { DocumentCollator, DocumentDecorator } from '@backstage/search-common';
import {
DocumentCollator,
DocumentDecorator,
IndexableDocument,
} from '@backstage/search-common';
import { Logger } from 'winston';
import { Scheduler } from './index';
import {
@@ -105,12 +109,29 @@ export class IndexBuilder {
this.logger.debug(
`Collating documents for ${type} via ${this.collators[type].collate.constructor.name}`,
);
let documents = await this.collators[type].collate.execute();
let documents: IndexableDocument[];
try {
documents = await this.collators[type].collate.execute();
} catch (e) {
this.logger.error(
`Collating documents for ${type} via ${this.collators[type].collate.constructor.name} failed: ${e}`,
);
return;
}
for (let i = 0; i < decorators.length; i++) {
this.logger.debug(
`Decorating ${type} documents via ${decorators[i].constructor.name}`,
);
documents = await decorators[i].execute(documents);
try {
documents = await decorators[i].execute(documents);
} catch (e) {
this.logger.error(
`Decorating ${type} documents via ${decorators[i].constructor.name} failed: ${e}`,
);
return;
}
}
if (!documents || documents.length === 0) {