Skip to content

Commit b5aa85a

Browse files
authored
Merge pull request #109 from DenisaCG/external_drive_error
Update error handling logic for adding public or external drives
2 parents 46b57a8 + 3092f5e commit b5aa85a

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

jupyter_drives/manager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ async def mount_drive(self, drive_name, provider, location=''):
319319
else:
320320
region = await self._get_drive_location(drive_name)
321321
self._initialize_content_manager(drive_name, provider, region)
322+
323+
# check if user is able to access drive
324+
check = await self._file_system._exists(drive_name + '/')
325+
if check is False:
326+
raise Exception('Failed to mount drive. Access denied.')
327+
322328
except Exception as e:
323329
raise tornado.web.HTTPError(
324330
status_code= httpx.codes.BAD_REQUEST,

src/plugins/driveBrowserPlugin.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
IToolbarWidgetRegistry,
2020
setToolbar,
2121
showDialog,
22-
Dialog
22+
Dialog,
23+
Notification
2324
} from '@jupyterlab/apputils';
2425
import { ISettingRegistry } from '@jupyterlab/settingregistry';
2526
import {
@@ -39,8 +40,9 @@ import { Widget } from '@lumino/widgets';
3940

4041
import { driveBrowserIcon, removeIcon } from '../icons';
4142
import { Drive } from '../contents';
42-
import { getContents, setListingLimit } from '../requests';
43+
import { getContents, mountDrive, setListingLimit } from '../requests';
4344
import { CommandIDs } from '../token';
45+
import { DrivesResponseError } from '../handler';
4446

4547
/**
4648
* Status bar widget for displaying drive information
@@ -535,9 +537,23 @@ namespace Private {
535537
ariaLabel: 'Add Drive'
536538
})
537539
]
538-
}).then(result => {
540+
}).then(async result => {
539541
if (result.value) {
540-
drive.addPublicDrive(result.value);
542+
const response = await mountDrive(result.value, {
543+
provider: 's3'
544+
});
545+
if (response && response.error) {
546+
// Show error in case of failure.
547+
Notification.emit(
548+
(response.error as DrivesResponseError).message,
549+
'error',
550+
{
551+
autoClose: 5000
552+
}
553+
);
554+
} else {
555+
drive.addPublicDrive(result.value);
556+
}
541557
}
542558
});
543559
},
@@ -567,9 +583,24 @@ namespace Private {
567583
ariaLabel: 'Add Drive'
568584
})
569585
]
570-
}).then(result => {
586+
}).then(async result => {
571587
if (result.value) {
572-
drive.addExternalDrive(result.value[0], result.value[1]);
588+
const response = await mountDrive(result.value[0], {
589+
provider: 's3',
590+
location: result.value[1]
591+
});
592+
if (response && response.error) {
593+
// Show error in case of failure.
594+
Notification.emit(
595+
(response.error as DrivesResponseError).message,
596+
'error',
597+
{
598+
autoClose: 5000
599+
}
600+
);
601+
} else {
602+
drive.addExternalDrive(result.value[0], result.value[1]);
603+
}
573604
}
574605
});
575606
},

0 commit comments

Comments
 (0)