Issue 47 - Improve error handling on result
This commit is contained in:
1 parent
9e55284329
commit
1ff1a8e355
3 files changed
+70
-20
No files matched your search
@@ -69,6 +69,10 @@ describe Google::APIClient::Result do
|
||||
@result = Google::APIClient::Result.new(@reference, @request, @response)
|
||||
end
|
||||
|
||||
it 'should indicate a successful response' do
|
||||
@result.error?.should be_false
|
||||
end
|
||||
|
||||
it 'should return the correct next page token' do
|
||||
@result.next_page_token.should == 'NEXT+PAGE+TOKEN'
|
||||
end
|
||||
@@ -144,5 +148,38 @@ describe Google::APIClient::Result do
|
||||
@result.data.items.should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with JSON error response' do
|
||||
before do
|
||||
@response.stub(:body).and_return(
|
||||
<<-END_OF_STRING
|
||||
{
|
||||
"error": {
|
||||
"errors": [
|
||||
{
|
||||
"domain": "global",
|
||||
"reason": "parseError",
|
||||
"message": "Parse Error"
|
||||
}
|
||||
],
|
||||
"code": 400,
|
||||
"message": "Parse Error"
|
||||
}
|
||||
}
|
||||
END_OF_STRING
|
||||
)
|
||||
@response.stub(:status).and_return(400)
|
||||
@result = Google::APIClient::Result.new(@reference, @request, @response)
|
||||
end
|
||||
|
||||
it 'should return error status correctly' do
|
||||
@result.error?.should be_true
|
||||
end
|
||||
|
||||
it 'should return the correct error message' do
|
||||
@result.error_message.should == 'Parse Error'
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user