Skip to content

Commit ef93d9a

Browse files
committed
use httpx.codes for manager functionalities
1 parent a3119ac commit ef93d9a

File tree

2 files changed

+22
-40
lines changed

2 files changed

+22
-40
lines changed

jupyter_drives/manager.py

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ async def list_drives(self):
7171
drives = [GCSDrive(self._config.access_key_id, self._config.secret_access_key)] # verfiy credentials needed
7272

7373
else:
74-
response = {
75-
"message": "Listing drives not supported for given provider.",
76-
"code": 501
77-
}
78-
return response
74+
raise tornado.web.HTTPError(
75+
status_code= httpx.codes.NOT_IMPLEMENTED,
76+
reason="Listing drives not supported for given provider.",
77+
)
7978

8079
results = []
8180
for drive in drives:
@@ -91,17 +90,15 @@ async def list_drives(self):
9190
"provider": self._config.provider
9291
}
9392
)
94-
response = {
95-
"data": data,
96-
"code": 200
97-
}
9893
else:
99-
response = {"code": 400, "message": "No credentials specified. Please set them in your user jupyter_server_config file."}
10094
raise tornado.web.HTTPError(
10195
status_code= httpx.codes.BAD_REQUEST,
10296
reason="No credentials specified. Please set them in your user jupyter_server_config file.",
10397
)
10498

99+
response = {
100+
"data": data
101+
}
105102
return response
106103

107104
async def mount_drive(self, drive_name, provider, region):
@@ -125,51 +122,36 @@ async def mount_drive(self, drive_name, provider, region):
125122

126123
self._content_managers[drive_name] = store
127124

128-
response = {
129-
"code": 201,
130-
"message": "Drive succesfully mounted."
131-
}
132125
else:
133-
response = {
134-
"code": 409,
135-
"message": "Drive already mounted."
136-
}
126+
raise tornado.web.HTTPError(
127+
status_code= httpx.codes.CONFLICT,
128+
reason= "Drive already mounted."
129+
)
137130

138131
except Exception as e:
139-
response = {
140-
"code": 400,
141-
"message": f"The following error occured when mouting the drive: {e}"
142-
}
143132
raise tornado.web.HTTPError(
144133
status_code= httpx.codes.BAD_REQUEST,
145134
reason= f"The following error occured when mouting the drive: {e}"
146135
)
147136

148-
return response
137+
return
149138

150-
async def unmount_drive(self, drive_name: str, **kwargs):
139+
async def unmount_drive(self, drive_name: str):
151140
"""Unmount a drive.
152141
153142
Args:
154143
drive_name: name of drive to unmount
155144
"""
156145
if drive_name in self._content_managers:
157146
self._content_managers.pop(drive_name, None)
158-
response = {
159-
"code": 204,
160-
"message": "Drive successfully unmounted."
161-
}
162147

163148
else:
164-
response = {
165-
"code": 404,
166-
"message": "Drive is not mounted or doesn't exist."}
167149
raise tornado.web.HTTPError(
168-
status_code= httpx.codes.BAD_REQUEST,
150+
status_code= httpx.codes.NOT_FOUND,
169151
reason="Drive is not mounted or doesn't exist.",
170152
)
171153

172-
return response
154+
return
173155

174156
async def get_contents(self, drive_name, path, **kwargs):
175157
"""Get contents of a file or directory.

src/contents.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ export class Drive implements Contents.IDrive {
195195
const currentDrive = this.drivesList.filter(x => x.name === localPath)[0];
196196
// when accessed the first time, mount drive
197197
if (!currentDrive.mounted) {
198-
const response = await mountDrive(localPath, {
199-
provider: currentDrive.provider,
200-
region: currentDrive.region
201-
});
202-
if (response.code === 200 || response.code === 409) {
198+
try {
199+
await mountDrive(localPath, {
200+
provider: currentDrive.provider,
201+
region: currentDrive.region
202+
});
203203
currentDrive.mounted = true;
204-
} else {
205-
console.error(response.message);
204+
} catch (e) {
205+
console.log(e);
206206
}
207207
}
208208

0 commit comments

Comments
 (0)