Skip to content

Commit 4090d98

Browse files
author
Jens Kürten
committed
Add Forbidden exception handling and update documentation for access checks
1 parent 8feb29f commit 4090d98

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

csfunctions/service/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class Unauthorized(Exception):
99
pass
1010

1111

12+
class Forbidden(Exception):
13+
pass
14+
15+
1216
class Conflict(Exception):
1317
pass
1418

@@ -52,6 +56,8 @@ def request(
5256

5357
if response.status_code == 401:
5458
raise Unauthorized
59+
if response.status_code == 403:
60+
raise Forbidden
5561
elif response.status_code == 409:
5662
raise Conflict
5763
elif response.status_code == 404:

csfunctions/service/file_upload.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ def upload_file_content(
143143
delete_derived_files: Whether to delete derived files after upload.
144144
145145
Raises:
146-
csfunctions.service.Unauthorized: If access check fails.
146+
csfunctions.service.Forbidden: If access check fails.
147+
csfunctions.service.Unauthorized: If the service token is invalid.
147148
csfunctions.service.Conflict: If the file is already locked.
148149
csfunctions.service.NotFound: If the file object does not exist.
149150
csfunctions.service.RateLimitExceeded: If the services rate limit is exceeded.
@@ -205,7 +206,8 @@ def upload_new_file(
205206
The ID of the newly created file object.
206207
207208
Raises:
208-
csfunctions.service.Unauthorized: If access check fails.
209+
csfunctions.service.Forbidden: If access check fails.
210+
csfunctions.service.Unauthorized: If the service token is invalid.
209211
csfunctions.service.NotFound: If the parent object does not exist.
210212
csfunctions.service.RateLimitExceeded: If the services rate limit is exceeded.
211213
"""

docs/reference/service.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ Creates a new file attached to the parent object and uploads content from the pr
7373

7474
**Exceptions:**
7575

76-
- `csfunctions.service.Unauthorized`: If access check fails.
76+
- `csfunctions.service.Unauthorized`: If th service token is invalid.
77+
- `csfunctions.service.Forbidden`: If access check fails.
7778
- `csfunctions.service.NotFound`: If the parent object does not exist.
7879

7980

@@ -119,7 +120,8 @@ Uploads new content to an existing file object, overwriting its previous content
119120

120121
**Exceptions:**
121122

122-
- `csfunctions.service.Unauthorized`: If access check fails.
123+
- `csfunctions.service.Unauthorized`: If th service token is invalid.
124+
- `csfunctions.service.Forbidden`: If access check fails.
123125
- `csfunctions.service.Conflict`: If the file is already locked.
124126
- `csfunctions.service.NotFound`: If the file object does not exist.
125127
- `csfunctions.service.RateLimitExceeded`: If the services rate limit is exceeded.

0 commit comments

Comments
 (0)