Skip to content

Commit 0693704

Browse files
committed
Add error handling examples
1 parent b02e116 commit 0693704

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,7 @@ Use a library like [MSAL](https://pypi.org/project/msal/) or [Azure Identity](ht
4646
```
4747
pip install -e .[tests]
4848
pytest # run unit tests
49-
```
49+
```
50+
51+
## Deployment
52+
Bump the version in `pyproject.toml` and `src/msdrive/__init__.py` and then run the `Upload Python Package` pipeline.

examples/onedrive/error_handling.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from msdrive import OneDrive
2+
from msdrive.exceptions import (
3+
DriveException,
4+
InvalidAccessToken,
5+
ItemNotFound,
6+
RateLimited,
7+
)
8+
9+
# Catch generic errors
10+
try:
11+
drive = OneDrive("access_token_here")
12+
drive.list_items()
13+
except DriveException as err:
14+
print("Something went wrong:", err)
15+
16+
17+
# Catch invalid access token
18+
try:
19+
drive = OneDrive("access_token_here")
20+
drive.list_items()
21+
except InvalidAccessToken as err:
22+
print("Invalid access token:", err)
23+
24+
25+
# Catch item not found
26+
try:
27+
drive = OneDrive("access_token_here")
28+
drive.list_items()
29+
except ItemNotFound as err:
30+
print("Item not found:", err)
31+
32+
33+
# Catch rate limit exceeded
34+
try:
35+
drive = OneDrive("access_token_here")
36+
drive.list_items()
37+
except RateLimited as err:
38+
print("Rate limited:", err)

examples/sharepoint/error_handling.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from msdrive import SharePoint
2+
from msdrive.exceptions import (
3+
DriveException,
4+
InvalidAccessToken,
5+
ItemNotFound,
6+
RateLimited,
7+
)
8+
9+
# Catch generic errors
10+
try:
11+
drive = SharePoint("access_token_here")
12+
drive.list_items()
13+
except DriveException as err:
14+
print("Something went wrong:", err)
15+
16+
17+
# Catch invalid access token
18+
try:
19+
drive = SharePoint("access_token_here")
20+
drive.list_items()
21+
except InvalidAccessToken as err:
22+
print("Invalid access token:", err)
23+
24+
25+
# Catch item not found
26+
try:
27+
drive = SharePoint("access_token_here")
28+
drive.list_items()
29+
except ItemNotFound as err:
30+
print("Item not found:", err)
31+
32+
33+
# Catch rate limit exceeded
34+
try:
35+
drive = SharePoint("access_token_here")
36+
drive.list_items()
37+
except RateLimited as err:
38+
print("Rate limited:", err)

0 commit comments

Comments
 (0)