Skip to content

Commit 94d010f

Browse files
author
Yoichi Kawasaki
committed
Added Exception handings for issue yokawasa#24
1 parent 90be8b4 commit 94d010f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

v2functions/http-trigger-blob-sas-token/__init__.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def main(req: func.HttpRequest) -> str:
142142
storage_key = ss[1]
143143
if not storage_account or not storage_key:
144144
return write_http_response(
145-
400,
145+
400,
146146
{ 'message': 'Function configuration error: NO Azure Storage connection string found!' }
147147
)
148148

@@ -159,13 +159,24 @@ def main(req: func.HttpRequest) -> str:
159159
try:
160160
req_body = req.get_json()
161161
except ValueError:
162-
pass
162+
# Case: Empty body
163+
return write_http_response(
164+
400,
165+
{ 'message': 'Invalid HTTP request body' }
166+
)
163167
else:
168+
# Case: Exception raised in get_json()
169+
if not 'req_body' in locals():
170+
return write_http_response(
171+
400,
172+
{ 'message': 'Invalid HTTP request body' }
173+
)
174+
# Case: Invalid parameters
164175
if not req_body.get('permission') or not req_body.get('container'):
165176
return write_http_response(
166177
400,
167178
{ 'message': 'Permission and container parameters must be included in HTTP request body' }
168-
)
179+
)
169180

170181
permission = req_body.get('permission')
171182
container_name = req_body.get('container')
@@ -175,9 +186,9 @@ def main(req: func.HttpRequest) -> str:
175186
token_ttl = int(req_body.get('ttl'))
176187
if token_ttl < 1:
177188
return write_http_response(
178-
400,
189+
400,
179190
{ 'message': 'Token ttl must be digit and more than 0' }
180-
)
191+
)
181192

182193
# Generate SAS Token
183194
token_dict = generate_sas_token(

0 commit comments

Comments
 (0)