Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jupyter_drives/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ async def mount_drive(self, drive_name, provider):
except Exception as e:
raise tornado.web.HTTPError(
status_code= httpx.codes.BAD_REQUEST,
reason= f"The following error occured when mouting the drive: {e}"
reason= f"{e}"
)

return
Expand Down Expand Up @@ -771,7 +771,7 @@ async def _get_drive_location(self, drive_name):
except Exception as e:
raise tornado.web.HTTPError(
status_code= httpx.codes.BAD_REQUEST,
reason=f"The following error occured when retriving the drive location: {e}",
reason=f"{e}",
)

return location
Expand Down
39 changes: 32 additions & 7 deletions src/plugins/drivelistmanager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
excludeDrive,
getDrivesList,
getExcludedDrives,
includeDrive
includeDrive,
mountDrive
} from '../requests';
import { ISignal, Signal } from '@lumino/signaling';
import { driveBrowserIcon, addIcon, removeIcon } from '../icons';
Expand All @@ -27,6 +28,8 @@ export interface IDriveInputProps {
onSubmit: () => void;
isPublic: boolean;
setIsPublic: (value: boolean) => void;
mountError: string;
resetMountError: () => void;
}

export function DriveInputComponent({
Expand All @@ -36,7 +39,9 @@ export function DriveInputComponent({
setRegion,
onSubmit,
isPublic,
setIsPublic
setIsPublic,
mountError,
resetMountError
}: IDriveInputProps) {
return (
<div>
Expand All @@ -45,6 +50,7 @@ export function DriveInputComponent({
className="drive-search-input"
onInput={(event: any) => {
setPublicDrive(event.target.value);
resetMountError();
}}
placeholder="Enter drive name"
value={driveValue}
Expand All @@ -69,12 +75,18 @@ export function DriveInputComponent({
className="drive-region-input"
onInput={(event: any) => {
setRegion(event.target.value);
resetMountError();
}}
placeholder="Region (e.g.: us-east-1)"
value={regionValue}
/>
)}
</div>
{mountError && (
<div className="add-public-drive-section">
<p className="error">{mountError}</p>
</div>
)}
</div>
);
}
Expand Down Expand Up @@ -183,6 +195,7 @@ export function DriveListManagerComponent({ model }: IProps) {
);
const [isPublic, setIsPublic] = useState<boolean>(false);
const [driveRegion, setDriveRegion] = useState<string>('');
const [mountError, setMountError] = useState<string>('');

// Called after mounting.
React.useEffect(() => {
Expand All @@ -197,14 +210,24 @@ export function DriveListManagerComponent({ model }: IProps) {
}, [model]);

const onAddedPublicDrive = async () => {
if (isPublic) {
await addPublicDrive(publicDrive);
// Check if user has access to drive.
const result = await mountDrive(publicDrive, {
provider: 's3'
});
if (result && result.error) {
// Show error in case of failure.
setMountError(result.error.message);
} else {
await addExternalDrive(publicDrive, driveRegion);
// Proceed with adding the drive otherwise.
if (isPublic) {
await addPublicDrive(publicDrive);
} else {
await addExternalDrive(publicDrive, driveRegion);
setDriveRegion('');
}
setDriveRegion('');
await model.refresh();
}
setPublicDrive('');
await model.refresh();
};

return (
Expand Down Expand Up @@ -239,6 +262,8 @@ export function DriveListManagerComponent({ model }: IProps) {
isPublic={isPublic}
setIsPublic={setIsPublic}
onSubmit={onAddedPublicDrive}
mountError={mountError}
resetMountError={() => setMountError('')}
/>
</div>

Expand Down
10 changes: 9 additions & 1 deletion src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ export async function mountDrive(
drive_name: driveName,
provider: options.provider
};
return await requestAPI<any>('drives', 'POST', body);
try {
await requestAPI<any>('drives', 'POST', body);
} catch (error: any) {
return {
error: error
};
}

return;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,8 @@ li {
fill: var(--jp-ui-inverse-font-color0) !important;
color: var(--jp-ui-inverse-font-color0) !important;
}

.error {
color: var(--md-red-600);
font-size: 0.7rem;
}
Loading