-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Surface HTML errors #121
Merged
Merged
Surface HTML errors #121
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eef3ed1
Extract error from HTML
betodealmeida 49eaaca
Fixes
betodealmeida 676b661
Fix JSONDecodeError
betodealmeida 39088ad
Sort keys so that unit test is deterministic
betodealmeida c4af287
Remove trailing whitespace in encoded JSON
betodealmeida d4f7747
Use textwrap and remove JSONDecodeError
betodealmeida File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,76 @@ def test_druid_returns_error(self, mock_urlopen): | |
threshold=1, | ||
context={"timeout": 1000}) | ||
|
||
@patch('pydruid.client.urllib.request.urlopen') | ||
def test_druid_returns_html_error(self, mock_urlopen): | ||
# given | ||
message = """<html> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: there's this trick indent long strings in code but not in the variable itself: s = textwrap.dedent"""\
this
wont
be indented
""" |
||
<head> | ||
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/> | ||
<title>Error 500 </title> | ||
</head> | ||
<body> | ||
<h2>HTTP ERROR: 500</h2> | ||
<p>Problem accessing /druid/v2/. Reason: | ||
<pre> javax.servlet.ServletException: java.lang.OutOfMemoryError: GC overhead limit exceeded</pre></p> | ||
<hr /><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.3.19.v20170502</a><hr/> | ||
</body> | ||
</html>""" | ||
ex = urllib.error.HTTPError(None, 500, message, None, None) | ||
mock_urlopen.side_effect = ex | ||
client = create_client() | ||
|
||
# when / then | ||
with pytest.raises(IOError) as e: | ||
client.topn( | ||
datasource="testdatasource", | ||
granularity="all", | ||
intervals="2015-12-29/pt1h", | ||
aggregations={"count": doublesum("count")}, | ||
dimension="user_name", | ||
metric="count", | ||
filter=Dimension("user_lang") == "en", | ||
threshold=1, | ||
context={"timeout": 1000}) | ||
|
||
assert str(e.value) == """HTTP Error 500: <html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/> | ||
<title>Error 500 </title> | ||
</head> | ||
<body> | ||
<h2>HTTP ERROR: 500</h2> | ||
<p>Problem accessing /druid/v2/. Reason: | ||
<pre> javax.servlet.ServletException: java.lang.OutOfMemoryError: GC overhead limit exceeded</pre></p> | ||
<hr /><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.3.19.v20170502</a><hr/> | ||
</body> | ||
</html> | ||
Druid Error: javax.servlet.ServletException: java.lang.OutOfMemoryError: GC overhead limit exceeded | ||
Query is: { | ||
"aggregations": [ | ||
{ | ||
"fieldName": "count", | ||
"name": "count", | ||
"type": "doubleSum" | ||
} | ||
], | ||
"context": { | ||
"timeout": 1000 | ||
}, | ||
"dataSource": "testdatasource", | ||
"dimension": "user_name", | ||
"filter": { | ||
"dimension": "user_lang", | ||
"type": "selector", | ||
"value": "en" | ||
}, | ||
"granularity": "all", | ||
"intervals": "2015-12-29/pt1h", | ||
"metric": "count", | ||
"queryType": "topN", | ||
"threshold": 1 | ||
}""" | ||
|
||
@patch('pydruid.client.urllib.request.urlopen') | ||
def test_druid_returns_results(self, mock_urlopen): | ||
# given | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like
JSONDecodeError
is derived fromValueError
, so catchingValueError
should just work and remove the need for this extra complexity.