summaryrefslogtreecommitdiff
path: root/lib/bitbucket_server
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-07-27 14:29:05 -0700
committerStan Hu <stanhu@gmail.com>2018-07-27 14:29:05 -0700
commit57d1b60f61a790c034b8d43ce2358371464d2d67 (patch)
treec1e625ab9ec32a89f51ca966c1b3245d3db1a1b6 /lib/bitbucket_server
parent450030e9029f5de6fcfb850e5940838c2a76c81e (diff)
downloadgitlab-ce-57d1b60f61a790c034b8d43ce2358371464d2d67.tar.gz
Handle invalid JSON from server
Diffstat (limited to 'lib/bitbucket_server')
-rw-r--r--lib/bitbucket_server/connection.rb13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/bitbucket_server/connection.rb b/lib/bitbucket_server/connection.rb
index 2d438ae8ca1..ee0888eeecf 100644
--- a/lib/bitbucket_server/connection.rb
+++ b/lib/bitbucket_server/connection.rb
@@ -59,16 +59,17 @@ module BitbucketServer
private
def check_errors!(response)
- return if response.code >= 200 && response.code < 300
+ raise ConnectionError, "Response is not valid JSON" unless response.parsed_response.is_a?(Hash)
- details =
- if response.parsed_response && response.parsed_response.is_a?(Hash)
- sanitize(response.parsed_response.dig('errors', 0, 'message'))
- end
+ return if response.code >= 200 && response.code < 300
+ details = sanitize(response.parsed_response.dig('errors', 0, 'message'))
message = "Error #{response.code}"
- message += ": #{details}" if details
+ message += ": #{details}"
+
raise ConnectionError, message
+ rescue JSON::ParserError
+ raise ConnectionError, "Unable to parse the server response as JSON"
end
def auth