Skip to content

Commit

Permalink
fix: catch errors when file attachment not found
Browse files Browse the repository at this point in the history
  • Loading branch information
sleidig committed Feb 19, 2024
1 parent 3ec317e commit 6da7fee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/app/features/file/couchdb-file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ export class CouchdbFileService extends FileService {
});
}

loadFile(entity: Entity, property: string): Observable<SafeUrl> {
loadFile(
entity: Entity,
property: string,
throwErrors: boolean = false,
): Observable<SafeUrl> {
const path = `${entity.getId()}/${property}`;
if (!this.cache[path]) {
this.cache[path] = this.http
Expand All @@ -168,6 +172,15 @@ export class CouchdbFileService extends FileService {
})
.pipe(
map((blob) => URL.createObjectURL(blob)),
catchError((err) => {
this.logger.warn(
`Could not load file (${entity?.getId()} . ${property}): ${err}`,
);
if (throwErrors) {
throw err;
}
return "";
}),
shareReplay(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/file/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export abstract class FileService {
protected constructor(
private entityMapper: EntityMapperService,
private entities: EntityRegistry,
private logger: LoggingService,
protected logger: LoggingService,
private syncState: SyncStateSubject,
) {
// TODO maybe registration is too late (only when component is rendered)
Expand Down

0 comments on commit 6da7fee

Please sign in to comment.