Skip to content

Commit

Permalink
Merge pull request #178 from SelfhostedPro/error-handling
Browse files Browse the repository at this point in the history
added rstrip to refresh_template
  • Loading branch information
SelfhostedPro authored Oct 19, 2020
2 parents 27284f2 + 8e3b6ee commit 0df1466
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions backend/api/db/crud/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,15 @@ def refresh_template(db: Session, template_id: id):
items = []
try:
with urllib.request.urlopen(template.url) as fp:
if ext in (".yml", '.yaml'):
if ext.rstrip() in (".yml", '.yaml'):
loaded_file = yaml.load(fp, Loader=yaml.SafeLoader)
elif ext in (".json"):
elif ext.rstrip() in (".json"):
loaded_file = json.load(fp)
else:
print('Invalid filetype')
raise
raise HTTPException(
status_code=422, detail="Invalid filetype"
)
if type(loaded_file) == list:
for entry in loaded_file:

Expand Down Expand Up @@ -209,7 +211,7 @@ def refresh_template(db: Session, template_id: id):
except Exception as exc:
print('Template update failed. ERR_001', exc)
raise HTTPException(
status_code=exc.response.status_code, detail=exc.explanation
status_code=exc.status_code, detail=exc.explanation
)
else:
# db.delete(template)
Expand Down

0 comments on commit 0df1466

Please sign in to comment.