almenscorner / IntuneCD

Tool to backup, update and document configurations in Intune
MIT License
290 stars 38 forks source link

Failure on HTTP 503 #36

Closed aaronparker closed 2 years ago

aaronparker commented 2 years ago

Describe the bug Not necessarily a bug, but an execption was rasied when the Graph API was unavailable. graph_request.py doesn't appear to handle HTTP 503 errors.

To Reproduce Difficult to reproduce because you'll need the Graph API to be unavailable. I wouldn't expect this to be an issue very often.

Expected behavior Not 100% sure, but graph_request.py could perhaps wait/retry or exit with an erorr.

Run type (please complete the following information):

Log

Traceback (most recent call last):
  File "/home/vsts/.local/bin/IntuneCD-startbackup", line 8, in <module>
    sys.exit(start())
  File "/home/vsts/.local/lib/python3.8/site-packages/IntuneCD/run_backup.py", line 136, in start
    run_backup(opts.path,opts.output,exclude,token)
  File "/home/vsts/.local/lib/python3.8/site-packages/IntuneCD/run_backup.py", line 68, in run_backup
    savebackup(path,output,exclude,token)
  File "/home/vsts/.local/lib/python3.8/site-packages/IntuneCD/backup_appConfiguration.py", line 49, in savebackup
    app_data = makeapirequest(app_endpoint + "/" + app_id, token)
  File "/home/vsts/.local/lib/python3.8/site-packages/IntuneCD/graph_request.py", line 38, in makeapirequest
    raise Exception('Request failed with ',response.status_code,' - ',
Exception: ('Request failed with ', 503, ' - ', '{"error":{"code":"UnknownError","message":"<!DOCTYPE HTML PUBLIC \\"-//W3C//DTD HTML 4.01//EN\\"\\"[http://www.w3.org/TR/html4/strict.dtd\\">\\r\\n<HTML><HEAD><TITLE>Service](http://www.w3.org/TR/html4/strict.dtd//%22%3E//r//n%3CHTML%3E%3CHEAD%3E%3CTITLE%3EService) Unavailable</TITLE>\\r\\n<META HTTP-EQUIV=\\"Content-Type\\" Content=\\"text/html; charset=us-ascii\\"></HEAD>\\r\\n<BODY><h2>Service Unavailable</h2>\\r\\n<hr><p>HTTP Error 503. The service is unavailable.</p>\\r\\n</BODY></HTML>\\r\\n","innerError":{"date":"2022-05-26T01:01:13","request-id":"c416c99b-a292-40bf-aed9-ab321f75ffc4","client-request-id":"c416c99b-a292-40bf-aed9-ab321f75ffc4"}}}')
##[error]Bash exited with code '1'.
##[error]Bash wrote one or more lines to the standard error stream.
##[error]Traceback (most recent call last):
  File "/home/vsts/.local/bin/IntuneCD-startbackup", line 8, in <module>
    sys.exit(start())
  File "/home/vsts/.local/lib/python3.8/site-packages/IntuneCD/run_backup.py", line 136, in start
    run_backup(opts.path,opts.output,exclude,token)
  File "/home/vsts/.local/lib/python3.8/site-packages/IntuneCD/run_backup.py", line 68, in run_backup
    savebackup(path,output,exclude,token)
  File "/home/vsts/.local/lib/python3.8/site-packages/IntuneCD/backup_appConfiguration.py", line 49, in savebackup
    app_data = makeapirequest(app_endpoint + "/" + app_id, token)
  File "/home/vsts/.local/lib/python3.8/site-packages/IntuneCD/graph_request.py", line 38, in makeapirequest
    raise Exception('Request failed with ',response.status_code,' - ',
Exception: ('Request failed with ', 503, ' - ', '{"error":{"code":"UnknownError","message":"<!DOCTYPE HTML PUBLIC \\"-//W3C//DTD HTML 4.01//EN\\"\\"[http://www.w3.org/TR/html4/strict.dtd\\">\\r\\n<HTML><HEAD><TITLE>Service](http://www.w3.org/TR/html4/strict.dtd//%22%3E//r//n%3CHTML%3E%3CHEAD%3E%3CTITLE%3EService) Unavailable</TITLE>\\r\\n<META HTTP-EQUIV=\\"Content-Type\\" Content=\\"text/html; charset=us-ascii\\"></HEAD>\\r\\n<BODY><h2>Service Unavailable</h2>\\r\\n<hr><p>HTTP Error 503. The service is unavailable.</p>\\r\\n</BODY></HTML>\\r\\n","innerError":{"date":"2022-05-26T01:01:13","request-id":"c416c99b-a292-40bf-aed9-ab321f75ffc4","client-request-id":"c416c99b-a292-40bf-aed9-ab321f75ffc4"}}}')
almenscorner commented 2 years ago

You are absolutely right, I added a retry for 502 and 504 but will make sure to include it for 503 as well in the next update!