Ver código fonte

Create special EVEAPIForbiddenError exception; catch in members module.

master
Ben Kurtovic 8 anos atrás
pai
commit
fbc9d8142c
3 arquivos alterados com 27 adições e 8 exclusões
  1. +4
    -2
      calefaction/eve/esi.py
  2. +15
    -2
      calefaction/exceptions.py
  3. +8
    -4
      calefaction/modules/members.py

+ 4
- 2
calefaction/eve/esi.py Ver arquivo

@@ -6,7 +6,7 @@ from threading import Lock

import requests

from ..exceptions import EVEAPIError
from ..exceptions import EVEAPIError, EVEAPIForbiddenError

__all__ = ["EVESwaggerInterface"]

@@ -196,8 +196,10 @@ class EVESwaggerInterface:
headers=headers, timeout=10)
resp.raise_for_status()
result = resp.json() if resp.content else None
except (requests.RequestException, ValueError):
except (requests.RequestException, ValueError) as exc:
self._logger.exception("ESI request failed")
if hasattr(exc, "response") and exc.response.status_code == 403:
raise EVEAPIForbiddenError()
raise EVEAPIError()

if can_cache and result is not None:


+ 15
- 2
calefaction/exceptions.py Ver arquivo

@@ -1,13 +1,26 @@
# -*- coding: utf-8 -*-

"""
This module contains exceptions for Calefaction.

+-- CalefactionError
+-- AccessDeniedError
+-- EVEAPIError
+-- EVEAPIForbiddenError
"""

class CalefactionError(RuntimeError):
"""Base exception class for errors within Calefaction."""
pass

class AccessDeniedError(CalefactionError):
"""The user tried to do something they don't have permission for."""
pass

class EVEAPIError(CalefactionError):
"""Represents (generally external) errors while using the EVE APIs."""
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

+ 8
- 4
calefaction/modules/members.py Ver arquivo

@@ -6,6 +6,7 @@ from flask import g
from flask_mako import render_template

from ._provided import blueprint
from ..exceptions import EVEAPIForbiddenError

SCOPES = {"esi-corporations.read_corporation_membership.v1"}

@@ -28,10 +29,13 @@ def get_members():
return []

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"],
"CEO" if item["character_id"] == ceo_id else None)


Carregando…
Cancelar
Salvar