1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Desktop, Cli, Mobile: Display an error if a resource cannot be downloaded

This commit is contained in:
Laurent Cozic
2024-01-14 12:35:20 +00:00
parent 7ebc98633a
commit cbf7e24c47

View File

@@ -182,20 +182,18 @@ export default class ResourceFetcher extends BaseService {
this.eventEmitter_.emit('downloadStarted', { id: resource.id }); this.eventEmitter_.emit('downloadStarted', { id: resource.id });
fileApi try {
.get(remoteResourceContentPath, { path: localResourceContentPath, target: 'file' }) const response = await fileApi.get(remoteResourceContentPath, { path: localResourceContentPath, target: 'file' });
// eslint-disable-next-line promise/prefer-await-to-then -- Old code before rule was applied if (!response) throw new Error(`Resource not found: ${resource.id}`);
.then(async () => {
await Resource.setLocalState(resource, { fetch_status: Resource.FETCH_STATUS_DONE }); await Resource.setLocalState(resource, { fetch_status: Resource.FETCH_STATUS_DONE });
this.logger().debug(`ResourceFetcher: Resource downloaded: ${resource.id}`); this.logger().debug(`ResourceFetcher: Resource downloaded: ${resource.id}`);
await completeDownload(true, localResourceContentPath); await completeDownload(true, localResourceContentPath);
}) } catch (error) {
// eslint-disable-next-line promise/prefer-await-to-then -- Old code before rule was applied this.logger().error(`ResourceFetcher: Could not download resource: ${resource.id}`, error);
.catch(async (error: any) => { await Resource.setLocalState(resource, { fetch_status: Resource.FETCH_STATUS_ERROR, fetch_error: error.message });
this.logger().error(`ResourceFetcher: Could not download resource: ${resource.id}`, error); await completeDownload();
await Resource.setLocalState(resource, { fetch_status: Resource.FETCH_STATUS_ERROR, fetch_error: error.message }); }
await completeDownload();
});
} }
private processQueue_() { private processQueue_() {