Skip to content

Commit 267d27f

Browse files
authored
Merge pull request #2024 from floccusaddon/fix/gdrive-error-handling
fix(GoogleDrive): Improve error handling
2 parents baaa3b1 + 30944a8 commit 267d27f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/lib/adapters/GoogleDrive.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,17 +437,29 @@ export default class GoogleDriveAdapter extends CachingAdapter {
437437

438438
async listFiles(query: string, limit = 1) : Promise<any> {
439439
const res = await this.request('GET', this.getUrl() + `/files?corpora=user&q=${encodeURIComponent(query)}&orderBy=modifiedTime%20desc&fields=files(id%2Cname%2Ctrashed)&pageSize=${limit}`)
440+
if (res.status >= 400) {
441+
Logger.log('Google API error: ' + JSON.stringify(res.text()))
442+
throw new HttpError(res.status, 'GET')
443+
}
440444
return res.json()
441445
}
442446

443447
async getFileMetadata(id: string, fields?:string): Promise<any> {
444448
const res = await this.request('GET', this.getUrl() + '/files/' + id + (fields ? `?fields=${encodeURIComponent(fields)}` : ''))
449+
if (res.status >= 400) {
450+
Logger.log('Google API error: ' + JSON.stringify(res.text()))
451+
throw new HttpError(res.status, 'GET')
452+
}
445453
return res.json()
446454
}
447455

448456
async downloadFile(id: string): Promise<string> {
449457
// We acknowledge abuse so that Google Drive will give us the file contents even if it thinks it's a virus.
450458
const res = await this.request('GET', this.getUrl() + '/files/' + id + '?alt=media' + '&acknowledgeAbuse=true')
459+
if (res.status >= 400) {
460+
Logger.log('Google API error: ' + JSON.stringify(res.text()))
461+
throw new HttpError(res.status, 'GET')
462+
}
451463
return res.text()
452464
}
453465

@@ -508,6 +520,10 @@ export default class GoogleDriveAdapter extends CachingAdapter {
508520

509521
async uploadFile(id:string, xbel: string) {
510522
const resp = await this.request('PATCH', 'https://www.googleapis.com/upload/drive/v3/files/' + id, xbel, 'application/xml')
523+
if (resp.status >= 400) {
524+
Logger.log('Google API error: ' + JSON.stringify(resp.text()))
525+
throw new HttpError(resp.status, 'GET')
526+
}
511527
return resp.status === 200
512528
}
513529
}

0 commit comments

Comments
 (0)