diff --git a/src/business_logic/formation/exceptions.py b/src/business_logic/formation/exceptions.py new file mode 100644 index 0000000..21827dc --- /dev/null +++ b/src/business_logic/formation/exceptions.py @@ -0,0 +1,6 @@ +class NoOnisepAPIException(Exception): + """ + Raised when we cannot communicate wit Onisep API + """ + + pass diff --git a/src/business_logic/formation/scrap/utils/get_onisep_data.py b/src/business_logic/formation/scrap/utils/get_onisep_data.py index 12b391d..7f2ffe3 100644 --- a/src/business_logic/formation/scrap/utils/get_onisep_data.py +++ b/src/business_logic/formation/scrap/utils/get_onisep_data.py @@ -2,6 +2,7 @@ # https://opendata.onisep.fr/data/5fa591127f501/2-ideo-formations-initiales-en-france.htm import requests from src.business_logic.formation import HEADERS, ONISEP_URL +from src.business_logic.formation.exceptions import NoOnisepAPIException DATASET = "5fa591127f501" @@ -12,4 +13,6 @@ def get_onisep_data(params: str) -> dict: response = requests.get(url, headers=HEADERS) if response.status_code == 200: return response.json() - raise Exception("Onisep API is down.", response.status_code) + raise NoOnisepAPIException( + f"status: {response.status_code} \n message : Onisep API is down. \n dataset : {DATASET} \n headers : {HEADERS} " + )