Skip to content

Commit

Permalink
http error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvdbergh committed Mar 2, 2018
1 parent b37a3bb commit 580037c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions scripts/filer.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,32 @@ def process_ftp_file(ftype, afile):
elif afile['type'] == 'DIRECTORY':
return process_upload_dir(afile['path'], ftp_path, ftp)
else:
print('Unknown file type: '+afile['type'])
logging.error('Unknown file type: '+afile['type'])
return 1
else:
print('Unknown file action: ' + ftype)
logging.error('Unknown file action: ' + ftype)
return 1

def process_http_file(ftype, afile):
if ftype == 'inputs':
r = requests.get(afile['url'])

if r.status_code != 200:
logging.error('Got status code: '+str(r.status_code))
return 1

fp = open(afile['path'], 'wb')
fp.write(r.content)
fp.close
return 0
elif ftype == 'outputs':
fp = open(afile['path'], 'r')
r = requests.put(afile['url'], data=fp.read())

if r.status_code != 200 or r.status_code != 201:
logging.error('Got status code: '+str(r.status_code))
return 1

fp.close
return 0
else:
Expand Down

0 comments on commit 580037c

Please sign in to comment.