Skip to content

Commit

Permalink
Handle json decode error in is.gd
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon committed Jan 20, 2024
1 parent 56f00cc commit aca8e43
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Run CloudBot",
"type": "python",
"request": "launch",
"module": "cloudbot",
"justMyCode": true
}
]
}
12 changes: 9 additions & 3 deletions cloudbot/util/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,23 @@ def paste(self, data, ext):

class Isgd(Shortener):
def shorten(self, url, custom=None, key=None):
p = {"url": url, "shorturl": custom, "format": "json"}
p = {"url": url, "format": "json"}
if custom:
p['shorturl'] = custom

try:
r = requests.get("http://is.gd/create.php", params=p)
r = requests.get("https://is.gd/create.php", params=p)
r.raise_for_status()
except HTTPError as e:
r = e.response
raise ServiceHTTPError(r.reason, r) from e
except RequestException as e:
raise ServiceError(e.request, "Connection error occurred") from e

j = r.json()
try:
j = r.json()
except requests.exceptions.JSONDecodeError as e:
raise ServiceError(r.request, str(e))

if "shorturl" in j:
return j["shorturl"]
Expand Down

0 comments on commit aca8e43

Please sign in to comment.