Skip to content

Commit 72099a2

Browse files
authored
Merge pull request #94 from DenisaCG/check_external_drive
Integrate error handling for adding external drive operation
2 parents b141389 + 7a6adce commit 72099a2

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

jupyter_drives/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ async def mount_drive(self, drive_name, provider):
319319
except Exception as e:
320320
raise tornado.web.HTTPError(
321321
status_code= httpx.codes.BAD_REQUEST,
322-
reason= f"The following error occured when mouting the drive: {e}"
322+
reason= f"{e}"
323323
)
324324

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

777777
return location

src/plugins/drivelistmanager.tsx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
excludeDrive,
1010
getDrivesList,
1111
getExcludedDrives,
12-
includeDrive
12+
includeDrive,
13+
mountDrive
1314
} from '../requests';
1415
import { ISignal, Signal } from '@lumino/signaling';
1516
import { driveBrowserIcon, addIcon, removeIcon } from '../icons';
@@ -27,6 +28,8 @@ export interface IDriveInputProps {
2728
onSubmit: () => void;
2829
isPublic: boolean;
2930
setIsPublic: (value: boolean) => void;
31+
mountError: string;
32+
resetMountError: () => void;
3033
}
3134

3235
export function DriveInputComponent({
@@ -36,7 +39,9 @@ export function DriveInputComponent({
3639
setRegion,
3740
onSubmit,
3841
isPublic,
39-
setIsPublic
42+
setIsPublic,
43+
mountError,
44+
resetMountError
4045
}: IDriveInputProps) {
4146
return (
4247
<div>
@@ -45,6 +50,7 @@ export function DriveInputComponent({
4550
className="drive-search-input"
4651
onInput={(event: any) => {
4752
setPublicDrive(event.target.value);
53+
resetMountError();
4854
}}
4955
placeholder="Enter drive name"
5056
value={driveValue}
@@ -69,12 +75,18 @@ export function DriveInputComponent({
6975
className="drive-region-input"
7076
onInput={(event: any) => {
7177
setRegion(event.target.value);
78+
resetMountError();
7279
}}
7380
placeholder="Region (e.g.: us-east-1)"
7481
value={regionValue}
7582
/>
7683
)}
7784
</div>
85+
{mountError && (
86+
<div className="add-public-drive-section">
87+
<p className="error">{mountError}</p>
88+
</div>
89+
)}
7890
</div>
7991
);
8092
}
@@ -183,6 +195,7 @@ export function DriveListManagerComponent({ model }: IProps) {
183195
);
184196
const [isPublic, setIsPublic] = useState<boolean>(false);
185197
const [driveRegion, setDriveRegion] = useState<string>('');
198+
const [mountError, setMountError] = useState<string>('');
186199

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

199212
const onAddedPublicDrive = async () => {
200-
if (isPublic) {
201-
await addPublicDrive(publicDrive);
213+
// Check if user has access to drive.
214+
const result = await mountDrive(publicDrive, {
215+
provider: 's3'
216+
});
217+
if (result && result.error) {
218+
// Show error in case of failure.
219+
setMountError(result.error.message);
202220
} else {
203-
await addExternalDrive(publicDrive, driveRegion);
221+
// Proceed with adding the drive otherwise.
222+
if (isPublic) {
223+
await addPublicDrive(publicDrive);
224+
} else {
225+
await addExternalDrive(publicDrive, driveRegion);
226+
setDriveRegion('');
227+
}
204228
setDriveRegion('');
229+
await model.refresh();
205230
}
206-
setPublicDrive('');
207-
await model.refresh();
208231
};
209232

210233
return (
@@ -239,6 +262,8 @@ export function DriveListManagerComponent({ model }: IProps) {
239262
isPublic={isPublic}
240263
setIsPublic={setIsPublic}
241264
onSubmit={onAddedPublicDrive}
265+
mountError={mountError}
266+
resetMountError={() => setMountError('')}
242267
/>
243268
</div>
244269

src/requests.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ export async function mountDrive(
7373
drive_name: driveName,
7474
provider: options.provider
7575
};
76-
return await requestAPI<any>('drives', 'POST', body);
76+
try {
77+
await requestAPI<any>('drives', 'POST', body);
78+
} catch (error: any) {
79+
return {
80+
error: error
81+
};
82+
}
83+
84+
return;
7785
}
7886

7987
/**

style/base.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,8 @@ li {
157157
fill: var(--jp-ui-inverse-font-color0) !important;
158158
color: var(--jp-ui-inverse-font-color0) !important;
159159
}
160+
161+
.error {
162+
color: var(--md-red-600);
163+
font-size: 0.7rem;
164+
}

0 commit comments

Comments
 (0)