Skip to content

Commit 8ea415a

Browse files
committed
clean up raises
1 parent acc4ae5 commit 8ea415a

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

fastcore/net.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# %% ../nbs/03b_net.ipynb 1
1818
from .utils import *
1919
from .parallel import *
20+
2021
from functools import wraps
21-
from pprint import pformat
2222
import json,urllib,contextlib
2323
import socket,urllib.request,http,urllib
2424
from contextlib import contextmanager,ExitStack
@@ -106,9 +106,8 @@ def urlopen(url, data=None, headers=None, timeout=None, **kwargs):
106106
if not isinstance(data, bytes): data = data.encode('ascii')
107107
try: return urlopener().open(urlwrap(url, data=data, headers=headers), timeout=timeout)
108108
except HTTPError as e:
109-
e.msg += f"\n====Error Body====\n{pformat(json.loads(e.read()))}"
110-
raise e
111-
except Exception as e: raise e
109+
e.msg += f"\n====Error Body====\n{e.read().decode(errors='ignore')}"
110+
raise
112111

113112
# %% ../nbs/03b_net.ipynb 20
114113
def urlread(url, data=None, headers=None, decode=True, return_json=False, return_headers=False, timeout=None, **kwargs):

nbs/03b_net.ipynb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"#|export\n",
1919
"from fastcore.utils import *\n",
2020
"from fastcore.parallel import *\n",
21+
"\n",
2122
"from functools import wraps\n",
22-
"from pprint import pformat\n",
2323
"import json,urllib,contextlib\n",
2424
"import socket,urllib.request,http,urllib\n",
2525
"from contextlib import contextmanager,ExitStack\n",
@@ -184,7 +184,7 @@
184184
"text/markdown": [
185185
"---\n",
186186
"\n",
187-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L64){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
187+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L63){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
188188
"\n",
189189
"#### HTTP4xxClientError\n",
190190
"\n",
@@ -195,7 +195,7 @@
195195
"text/plain": [
196196
"---\n",
197197
"\n",
198-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L64){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
198+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L63){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
199199
"\n",
200200
"#### HTTP4xxClientError\n",
201201
"\n",
@@ -223,7 +223,7 @@
223223
"text/markdown": [
224224
"---\n",
225225
"\n",
226-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L69){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
226+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L68){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
227227
"\n",
228228
"#### HTTP5xxServerError\n",
229229
"\n",
@@ -234,7 +234,7 @@
234234
"text/plain": [
235235
"---\n",
236236
"\n",
237-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L69){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
237+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/net.py#L68){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
238238
"\n",
239239
"#### HTTP5xxServerError\n",
240240
"\n",
@@ -315,9 +315,8 @@
315315
" if not isinstance(data, bytes): data = data.encode('ascii')\n",
316316
" try: return urlopener().open(urlwrap(url, data=data, headers=headers), timeout=timeout)\n",
317317
" except HTTPError as e: \n",
318-
" e.msg += f\"\\n====Error Body====\\n{pformat(json.loads(e.read()))}\"\n",
319-
" raise e\n",
320-
" except Exception as e: raise e"
318+
" e.msg += f\"\\n====Error Body====\\n{e.read().decode(errors='ignore')}\"\n",
319+
" raise"
321320
]
322321
},
323322
{
@@ -338,7 +337,11 @@
338337
"text": [
339338
"404 Not Found\n",
340339
"====Error Body====\n",
341-
"{'documentation_url': 'https://docs.github.com/rest', 'message': 'Not Found'}\n"
340+
"{\n",
341+
" \"message\": \"Not Found\",\n",
342+
" \"documentation_url\": \"https://docs.github.com/rest\"\n",
343+
"}\n",
344+
"\n"
342345
]
343346
}
344347
],

0 commit comments

Comments
 (0)