Skip to content

Commit

Permalink
Handle BadStatusLine errors
Browse files Browse the repository at this point in the history
As far as I can tell this is really an issue in urllib2 as that should
really catch and handle this error as URLError or HTTPError. But it
doesn't seem to. More details/info in the issue.

Fixes: simplenote-vim#24
  • Loading branch information
atomicules committed Jun 2, 2019
1 parent a2342d6 commit 74da92f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
History
========

2.1.4 (2019-06-02)
------------------

* Handle BadStatusLine errors

2.1.3 (2019-06-01)
------------------

Expand Down
2 changes: 1 addition & 1 deletion simplenote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from .simplenote import Simplenote, SimplenoteLoginFailed

__author__ = "Daniel Schauenberg"
__version__ = "2.1.3"
__version__ = "2.1.4"
__license__ = "MIT"
14 changes: 8 additions & 6 deletions simplenote/simplenote.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
from urllib.error import HTTPError
import urllib.parse as urllib
import html
from http.client import BadStatusLine
else:
import urllib2
from urllib2 import HTTPError
import urllib
from HTMLParser import HTMLParser
from httplib import BadStatusLine

import base64
import time
Expand Down Expand Up @@ -81,7 +83,7 @@ def authenticate(self, user, password):
try:
res = urllib2.urlopen(request).read()
token = json.loads(res.decode('utf-8'))["access_token"]
except HTTPError:
except (HTTPError, BadStatusLine):
raise SimplenoteLoginFailed('Login to Simplenote API failed!')
except IOError: # no connection exception
token = None
Expand Down Expand Up @@ -133,7 +135,7 @@ def get_note(self, noteid, version=None):
raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.')
else:
return e, -1
except IOError as e:
except (IOError, BadStatusLine) as e:
return e, -1
note = json.loads(response.read().decode('utf-8'))
note = self.__add_simplenote_api_fields(note, noteid, int(response.info().get("X-Simperium-Version")))
Expand Down Expand Up @@ -191,7 +193,7 @@ def update_note(self, note):
raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.')
else:
return e, -1
except IOError as e:
except (IOError, BadStatusLine) as e:
return e, -1
note_to_update = json.loads(response.read().decode('utf-8'))
note_to_update = self.__add_simplenote_api_fields(note_to_update, noteid, int(response.info().get("X-Simperium-Version")))
Expand Down Expand Up @@ -284,7 +286,7 @@ def get_note_list(self, data=True, since=None, tags=[]):
raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.')
else:
return e, -1
except IOError as e:
except (IOError, BadStatusLine) as e:
return e, -1

# get additional notes if bookmark was set in response
Expand All @@ -311,7 +313,7 @@ def get_note_list(self, data=True, since=None, tags=[]):
raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.')
else:
return e, -1
except IOError as e:
except (IOError, BadStatusLine) as e:
return e, -1
note_list = notes["index"]
self.current = response_notes["current"]
Expand Down Expand Up @@ -371,7 +373,7 @@ def delete_note(self, note_id):
request.add_header(self.header, self.get_token())
try:
response = urllib2.urlopen(request)
except IOError as e:
except (IOError, BadStatusLine) as e:
return e, -1
except HTTPError as e:
if e.code == 401:
Expand Down

0 comments on commit 74da92f

Please sign in to comment.