Skip to content

Commit f2acf2d

Browse files
committed
Added try/except to catch errors
1 parent df23ea4 commit f2acf2d

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

app-auth/graphapponlytutorial/main.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# <ProgramSnippet>
55
import asyncio
66
import configparser
7+
from msgraph.generated.models.o_data_errors.o_data_error import ODataError
78
from graph import Graph
89

910
async def main():
@@ -30,16 +31,21 @@ async def main():
3031
except ValueError:
3132
choice = -1
3233

33-
if choice == 0:
34-
print('Goodbye...')
35-
elif choice == 1:
36-
await display_access_token(graph)
37-
elif choice == 2:
38-
await list_users(graph)
39-
elif choice == 3:
40-
await make_graph_call(graph)
41-
else:
42-
print('Invalid choice!\n')
34+
try:
35+
if choice == 0:
36+
print('Goodbye...')
37+
elif choice == 1:
38+
await display_access_token(graph)
39+
elif choice == 2:
40+
await list_users(graph)
41+
elif choice == 3:
42+
await make_graph_call(graph)
43+
else:
44+
print('Invalid choice!\n')
45+
except ODataError as odata_error:
46+
print('Error:')
47+
if odata_error.error:
48+
print(odata_error.error.code, odata_error.error.message)
4349
# </ProgramSnippet>
4450

4551
# <DisplayAccessTokenSnippet>
@@ -53,7 +59,7 @@ async def list_users(graph: Graph):
5359
users_page = await graph.get_users()
5460

5561
# Output each users's details
56-
if users_page is not None and users_page.value is not None:
62+
if users_page and users_page.value:
5763
for user in users_page.value:
5864
print('User:', user.display_name)
5965
print(' ID:', user.id)

app-auth/graphapponlytutorial/pylintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,5 +576,5 @@ preferred-modules=
576576

577577
# Exceptions that will emit a warning when being caught. Defaults to
578578
# "BaseException, Exception".
579-
overgeneral-exceptions=BaseException,
580-
Exception
579+
overgeneral-exceptions=builtins.BaseException,
580+
builtins.Exception

0 commit comments

Comments
 (0)