Skip to content

Commit dc91de1

Browse files
committed
Add try/except to catch errors
1 parent 7a9a6f2 commit dc91de1

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

user-auth/graphtutorial/main.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import asyncio
66
import configparser
77
from graph import Graph
8+
from msgraph.generated.models.o_data_errors.o_data_error import ODataError
89

910
async def main():
1011
print('Python Graph Tutorial\n')
@@ -33,18 +34,23 @@ async def main():
3334
except ValueError:
3435
choice = -1
3536

36-
if choice == 0:
37-
print('Goodbye...')
38-
elif choice == 1:
39-
await display_access_token(graph)
40-
elif choice == 2:
41-
await list_inbox(graph)
42-
elif choice == 3:
43-
await send_mail(graph)
44-
elif choice == 4:
45-
await make_graph_call(graph)
46-
else:
47-
print('Invalid choice!\n')
37+
try:
38+
if choice == 0:
39+
print('Goodbye...')
40+
elif choice == 1:
41+
await display_access_token(graph)
42+
elif choice == 2:
43+
await list_inbox(graph)
44+
elif choice == 3:
45+
await send_mail(graph)
46+
elif choice == 4:
47+
await make_graph_call(graph)
48+
else:
49+
print('Invalid choice!\n')
50+
except ODataError as e:
51+
print('Error:')
52+
if e.error is not None:
53+
print(e.error.code, e.error.message)
4854
# </ProgramSnippet>
4955

5056
# <GreetUserSnippet>

0 commit comments

Comments
 (0)