Skip to content

Commit a573972

Browse files
committed
Handle additional error codes
It seems the 'detail' key referenced in commit d9c7ced is present for 404 cases. This means we can show a nice message for this particular instance. On the other hand, if there's a bug with the Patchwork server and a 5xx code is raised, we should raise that promptly. Signed-off-by: Stephen Finucane <stephen@that.guru> Closes: #189
1 parent 8ad2d1e commit a573972

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

git_pw/api.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,17 @@ def _get_project(): # type: () -> str
8080

8181
def _handle_error(operation, exc):
8282
if exc.response is not None and exc.response.content:
83+
# server errors should always be reported
84+
if exc.response.status_code in range(500, 512): # 5xx Server Error
85+
LOG.error('Server error. Please report this issue to '
86+
'https://github.com/getpatchwork/patchwork')
87+
raise
88+
8389
# we make the assumption that all responses will be JSON encoded
84-
LOG.error(exc.response.json())
90+
if exc.response.status_code == 404:
91+
LOG.error('Resource not found')
92+
else:
93+
LOG.error(exc.response.json())
8594
else:
8695
LOG.error('Failed to %s resource. Is your configuration '
8796
'correct?' % operation)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
HTTP 404 and HTTP 5xx errors are now handled correctly.

0 commit comments

Comments
 (0)