Catch invalid responses from Sentry's API and treat them as expected errors

Fixes #5
This commit is contained in:
R. Tyler Croy 2017-09-04 10:30:57 -07:00
parent 6e1a1ef172
commit 3419d199e9
No known key found for this signature in database
GPG Key ID: 1426C7DC3F51E16F
2 changed files with 13 additions and 4 deletions

View File

@ -27,7 +27,7 @@ module CodeValet::Canary::DAO
:expires_in => 10 * CACHE_SECONDS) do
SentryApi.projects
end
rescue *CodeValet::Canary::DAO::NET_ERRORS => e
rescue *CodeValet::Canary::DAO::NET_ERRORS, SentryApi::Error::Parsing => e
@error = e
return []
rescue StandardError => e
@ -46,7 +46,7 @@ module CodeValet::Canary::DAO
:expires_in => CACHE_SECONDS) do
SentryApi.project_issues(project_key)
end
rescue *CodeValet::Canary::DAO::NET_ERRORS => e
rescue *CodeValet::Canary::DAO::NET_ERRORS, SentryApi::Error::Parsing => e
@error = e
return []
rescue StandardError => e
@ -67,7 +67,7 @@ module CodeValet::Canary::DAO
:expires_in => 5 * CACHE_SECONDS) do
SentryApi.issue(id)
end
rescue *CodeValet::Canary::DAO::NET_ERRORS => e
rescue *CodeValet::Canary::DAO::NET_ERRORS, SentryApi::Error::Parsing => e
@error = e
return nil
rescue StandardError => e
@ -81,7 +81,7 @@ module CodeValet::Canary::DAO
:expires_in => CACHE_SECONDS) do
SentryApi.issue_events(id)
end
rescue *CodeValet::Canary::DAO::NET_ERRORS => e
rescue *CodeValet::Canary::DAO::NET_ERRORS, SentryApi::Error::Parsing => e
@error = e
return nil
rescue StandardError => e

View File

@ -64,6 +64,15 @@ describe CodeValet::Canary::DAO::Sentry do
expect(dao).to be_errored
end
# https://github.com/CodeValet/canary/issues/5
it 'should gracefully handle Sentry API parsing errors' do
expect(SentryApi).to receive(:project_issues).and_raise(SentryApi::Error::Parsing)
expect(Raven).not_to receive(:capture_exception)
expect(issues).to be_empty
expect(dao).to be_errored
end
it 'should gracefully handle and record unknown errors' do
expect(SentryApi).to receive(:project_issues).and_raise(JSON::ParserError)
expect(Raven).to receive(:capture_exception)