| @@ -6,7 +6,7 @@ from threading import Lock | |||||
| import requests | import requests | ||||
| from ..exceptions import EVEAPIError | |||||
| from ..exceptions import EVEAPIError, EVEAPIForbiddenError | |||||
| __all__ = ["EVESwaggerInterface"] | __all__ = ["EVESwaggerInterface"] | ||||
| @@ -196,8 +196,10 @@ class EVESwaggerInterface: | |||||
| headers=headers, timeout=10) | headers=headers, timeout=10) | ||||
| resp.raise_for_status() | resp.raise_for_status() | ||||
| result = resp.json() if resp.content else None | result = resp.json() if resp.content else None | ||||
| except (requests.RequestException, ValueError): | |||||
| except (requests.RequestException, ValueError) as exc: | |||||
| self._logger.exception("ESI request failed") | self._logger.exception("ESI request failed") | ||||
| if hasattr(exc, "response") and exc.response.status_code == 403: | |||||
| raise EVEAPIForbiddenError() | |||||
| raise EVEAPIError() | raise EVEAPIError() | ||||
| if can_cache and result is not None: | if can_cache and result is not None: | ||||
| @@ -1,13 +1,26 @@ | |||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||
| """ | |||||
| This module contains exceptions for Calefaction. | |||||
| +-- CalefactionError | |||||
| +-- AccessDeniedError | |||||
| +-- EVEAPIError | |||||
| +-- EVEAPIForbiddenError | |||||
| """ | |||||
| class CalefactionError(RuntimeError): | class CalefactionError(RuntimeError): | ||||
| """Base exception class for errors within Calefaction.""" | """Base exception class for errors within Calefaction.""" | ||||
| pass | pass | ||||
| class AccessDeniedError(CalefactionError): | |||||
| """The user tried to do something they don't have permission for.""" | |||||
| pass | |||||
| class EVEAPIError(CalefactionError): | class EVEAPIError(CalefactionError): | ||||
| """Represents (generally external) errors while using the EVE APIs.""" | """Represents (generally external) errors while using the EVE APIs.""" | ||||
| pass | pass | ||||
| class AccessDeniedError(CalefactionError): | |||||
| """The user tried to do something they don't have permission for.""" | |||||
| class EVEAPIForbiddenError(EVEAPIError): | |||||
| """We tried to make an API request that we don't have permission for.""" | |||||
| pass | pass | ||||
| @@ -6,6 +6,7 @@ from flask import g | |||||
| from flask_mako import render_template | from flask_mako import render_template | ||||
| from ._provided import blueprint | from ._provided import blueprint | ||||
| from ..exceptions import EVEAPIForbiddenError | |||||
| SCOPES = {"esi-corporations.read_corporation_membership.v1"} | SCOPES = {"esi-corporations.read_corporation_membership.v1"} | ||||
| @@ -28,10 +29,13 @@ def get_members(): | |||||
| return [] | return [] | ||||
| corp_id = g.config.get("corp.id") | corp_id = g.config.get("corp.id") | ||||
| resp = g.eve.esi(token).v2.corporations(corp_id).members.get() | |||||
| cids = ",".join(str(item["character_id"]) for item in resp) | |||||
| ceo_id = g.eve.esi(token).v2.corporations(corp_id).get()["ceo_id"] | |||||
| resp = g.eve.esi(token).v1.characters.names.get(character_ids=cids) | |||||
| try: | |||||
| ceo_id = g.eve.esi(token).v2.corporations(corp_id).get()["ceo_id"] | |||||
| cids_r = g.eve.esi(token).v2.corporations(corp_id).members.get() | |||||
| cids = ",".join(sorted(str(item["character_id"]) for item in cids_r)) | |||||
| resp = g.eve.esi(token).v1.characters.names.get(character_ids=cids) | |||||
| except EVEAPIForbiddenError: | |||||
| return [] | |||||
| members = [_Member(item["character_id"], item["character_name"], | members = [_Member(item["character_id"], item["character_name"], | ||||
| "CEO" if item["character_id"] == ceo_id else None) | "CEO" if item["character_id"] == ceo_id else None) | ||||