Skip to content

Commit

Permalink
feat: add error for when a user is region blocked
Browse files Browse the repository at this point in the history
  • Loading branch information
Strvm committed Apr 22, 2024
1 parent 131a80d commit 5904e52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/meta_ai_api/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
class FacebookInvalidCredentialsException(Exception):
pass


class FacebookRegionBlocked(Exception):
pass
10 changes: 9 additions & 1 deletion src/meta_ai_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from meta_ai_api.utils import get_fb_session

from meta_ai_api.exceptions import FacebookRegionBlocked

MAX_RETRIES = 3


Expand Down Expand Up @@ -68,7 +70,13 @@ def get_access_token(self) -> str:
}

response = self.session.post(url, headers=headers, data=payload)
auth_json = response.json()
try:
auth_json = response.json()
except json.JSONDecodeError:
raise FacebookRegionBlocked(
"Unable to receive a valid response from Meta AI. This is likely due to your region being blocked. "
"Try manually accessing https://www.meta.ai/ to confirm."
)
access_token = auth_json["data"]["xab_abra_accept_terms_of_service"][
"new_temp_user_auth"
]["access_token"]
Expand Down

0 comments on commit 5904e52

Please sign in to comment.