Skip to content

Commit 8f97bae

Browse files
committed
fix: Throw nice error for when gdrive search fails
fixes #1845 Signed-off-by: Marcel Klehr <[email protected]>
1 parent 23dcf0e commit 8f97bae

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

_locales/en/messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@
116116
"Error039": {
117117
"message": "E039: Failed to update the following bookmark on the server: {0}"
118118
},
119+
"Error040": {
120+
"message": "E040: Could not search for your file name in your Google Drive"
121+
},
119122
"LabelWebdavurl": {
120123
"message": "WebDAV URL"
121124
},

src/errors/Error.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,12 @@ export class UpdateBookmarkError extends FloccusError {
333333
this.bookmark = bookmark
334334
Object.setPrototypeOf(this, UpdateBookmarkError.prototype)
335335
}
336+
}
337+
338+
export class GoogleDriveSearchError extends FloccusError {
339+
constructor() {
340+
super('E040: Could not search for your file name in your Google Drive')
341+
this.code = 40
342+
Object.setPrototypeOf(this, GoogleDriveSearchError.prototype)
343+
}
336344
}

src/lib/adapters/GoogleDrive.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
DecryptionError, FileUnreadableError,
99
GoogleDriveAuthenticationError, HttpError, CancelledSyncError, MissingPermissionsError,
1010
NetworkError,
11-
OAuthTokenError, ResourceLockedError
11+
OAuthTokenError, ResourceLockedError, GoogleDriveSearchError
1212
} from '../../errors/Error'
1313
import { OAuth2Client } from '@byteowls/capacitor-oauth2'
1414
import { Capacitor, CapacitorHttp as Http } from '@capacitor/core'
@@ -216,6 +216,10 @@ export default class GoogleDriveAdapter extends CachingAdapter {
216216
this.accessToken = await this.getAccessToken(this.server.refreshToken)
217217

218218
const fileList = await this.listFiles(`name = '${this.server.bookmark_file}'`, 100)
219+
if (!fileList.files) {
220+
throw new GoogleDriveSearchError()
221+
}
222+
219223
const file = fileList.files.filter(file => !file.trashed)[0]
220224

221225
const filesToDelete = fileList.files.filter(file => !file.trashed).slice(1)

0 commit comments

Comments
 (0)