Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
57d1b60f
Commit
57d1b60f
authored
Jul 27, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle invalid JSON from server
parent
450030e9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
6 deletions
+13
-6
lib/bitbucket_server/connection.rb
lib/bitbucket_server/connection.rb
+7
-6
spec/lib/bitbucket_server/connection_spec.rb
spec/lib/bitbucket_server/connection_spec.rb
+6
-0
No files found.
lib/bitbucket_server/connection.rb
View file @
57d1b60f
...
...
@@ -59,16 +59,17 @@ module BitbucketServer
private
def
check_errors!
(
response
)
r
eturn
if
response
.
code
>=
200
&&
response
.
code
<
300
r
aise
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
...
...
spec/lib/bitbucket_server/connection_spec.rb
View file @
57d1b60f
...
...
@@ -20,6 +20,12 @@ describe BitbucketServer::Connection do
expect
{
subject
.
get
(
url
)
}.
to
raise_error
(
described_class
::
ConnectionError
)
end
it
'throws an exception if the response is not JSON'
do
WebMock
.
stub_request
(
:get
,
url
).
with
(
headers:
{
'Accept'
=>
'application/json'
}).
to_return
(
body:
'bad data'
,
status:
200
,
headers:
headers
)
expect
{
subject
.
get
(
url
)
}.
to
raise_error
(
described_class
::
ConnectionError
)
end
end
describe
'#post'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment