diff --git a/CHANGELOG.md b/CHANGELOG.md index bfd75d0a..3d6aca2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ #Changelog +* 1.1.4 + * Fixes + * Fixed error handling for invalidated refresh tokens * 1.1.3 * Fixes * Fixed error in handling sse requests diff --git a/waitlist/blueprints/api/fittings/self.py b/waitlist/blueprints/api/fittings/self.py index f80c3ffe..dc89ed8b 100644 --- a/waitlist/blueprints/api/fittings/self.py +++ b/waitlist/blueprints/api/fittings/self.py @@ -17,6 +17,13 @@ def self_remove_fit(fitid): # remove one of your fittings by id fit = db.session.query(Shipfit).filter(Shipfit.id == fitid).first() + # this fit is not on any waitlist + # if we get this case it means some ones UI did not update + if fit.waitlist is None: + logger.info(f"{current_user.get_eve_name()} tried to remove own fit with id={fit.id}" + f" while it was not on any waitlist anymore") + return "This fit is not on a waitlist anymore" + wlentry = db.session.query(WaitlistEntry).filter(WaitlistEntry.id == fit.waitlist.id).first() if wlentry.user == current_user.get_eve_id(): diff --git a/waitlist/data/version.py b/waitlist/data/version.py index 34c05dc0..0a800830 100644 --- a/waitlist/data/version.py +++ b/waitlist/data/version.py @@ -1 +1 @@ -version = "1.1.3-$Format:%h$" +version = "1.1.4-$Format:%h$" diff --git a/waitlist/utility/swagger/patch.py b/waitlist/utility/swagger/patch.py index 501dbc6d..bf24613d 100644 --- a/waitlist/utility/swagger/patch.py +++ b/waitlist/utility/swagger/patch.py @@ -8,14 +8,24 @@ from esipy.cache import DictCache, BaseCache, DummyCache from esipy.events import api_call_stats +from esipy.exceptions import APIException +from flask_login import current_user from pyswagger.core import BaseClient from requests import Session, Request import six from requests.adapters import HTTPAdapter +from waitlist import db + logger = logging.getLogger(__name__) +class DummyResp(object): + def __init__(self, resp, status_code): + self.data = resp + self.status = status_code + + class EsiClient(BaseClient): __schemes__ = {'https'} @@ -90,8 +100,25 @@ def request(self, req_and_resp, raw_body_only=None, opt=None): if opt is None: opt = {} - # required because of inheritance - request, response = super(EsiClient, self).request(req_and_resp, opt) + + try: + # required because of inheritance + request, response = super(EsiClient, self).request(req_and_resp, opt) + except APIException as e: + logger.info("Failed to execute request", e) + ermsg = "No Message" + if 'error' in e.response: + ermsg = e.response['error'] + elif 'message' in e.response: + ermsg = e.response['message'] + + if e.status_code == 400 and ermsg == "invalid_token": + # since the token is invalid lets delete it + db.session.remove(current_user.ssoToken) + db.session.commit() + + # fake a response that has the fields as expected + return DummyResp(e.response, e.status_code) # check cache here so we have all headers, formed url and params cache_key = self.__make_cache_key(request)