Skip to content

Commit

Permalink
fix: handle bad token error
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed Apr 4, 2022
1 parent d492a3f commit 437208f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
26 changes: 17 additions & 9 deletions enex2notion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Optional

from notion.client import NotionClient
from requests import HTTPError, codes

from enex2notion.cli_wkhtmltopdf import ensure_wkhtmltopdf
from enex2notion.enex_parser import iter_notes
Expand Down Expand Up @@ -119,15 +120,7 @@ def cli(argv):
if args.mode_webclips == "PDF":
ensure_wkhtmltopdf()

if args.token:
root = get_import_root(
NotionClient(token_v2=args.token), "Evernote ENEX Import"
)
else:
logger.warning(
"No token provided, dry run mode. Nothing will be uploaded to Notion!"
)
root = None
root = get_root(args.token)

enex_uploader = EnexUploader(
import_root=root,
Expand All @@ -147,6 +140,21 @@ def cli(argv):
enex_uploader.upload(enex_input)


def get_root(token):
if not token:
logger.warning(
"No token provided, dry run mode. Nothing will be uploaded to Notion!"
)
return None

try:
return get_import_root(NotionClient(token_v2=token), "Evernote ENEX Import")
except HTTPError as e:
if e.response.status_code == codes["unauthorized"]:
logger.error("Invalid token provided!")
sys.exit(1)


def main(): # pragma: no cover
try:
cli(sys.argv[1:])
Expand Down
1 change: 0 additions & 1 deletion enex2notion/note_parser_webclip_pdf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import hashlib
import io
import logging
import re
from base64 import b64encode
Expand Down

0 comments on commit 437208f

Please sign in to comment.