Skip to content

Commit 38be3fb

Browse files
committed
Don't log invalid token in sentry
Sentry should be for exceptional errors. Having this reported to sentry was creating a lot of noise (~20k events a day) and using up a large proportion of our Sentry limits. If in the future we want to track this, we should instead log it or track unauthorized responses as a proxy. Before doing this I did some testing to see if the tokens were long lasting and are automatically refresh - as far as I can see they are and wasn't able to reproduce any issues by leaving tabs open or by offloading tabs. This would point to most tokens being invalid due to expiry. This could be due to the refresh token not working in inactive tabs.
1 parent a936104 commit 38be3fb

2 files changed

Lines changed: 4 additions & 16 deletions

File tree

lib/hydra_public_api_client.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def fetch_oauth_user(token:)
1818

1919
response = get('userinfo', {}, { Authorization: "Bearer #{token}" })
2020
response.body.to_h
21-
rescue Faraday::UnauthorizedError => e
22-
Sentry.capture_exception(e)
21+
rescue Faraday::UnauthorizedError
2322
nil
2423
end
2524

spec/models/user_spec.rb

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,9 @@
120120
end
121121
end
122122

123-
context 'when the access token is invalid' do
124-
before do
125-
allow(Sentry).to receive(:capture_exception)
126-
stub_request(:get, "#{HydraPublicApiClient::API_URL}/userinfo").to_return(status: 401)
127-
end
128-
129-
it 'returns nil' do
130-
expect(user).to be_nil
131-
end
132-
133-
it 'reports the Faraday::UnauthorizedError exception to Sentry' do
134-
user
135-
expect(Sentry).to have_received(:capture_exception).with(instance_of(Faraday::UnauthorizedError))
136-
end
123+
it 'returns nil when the access token is invalid' do
124+
stub_request(:get, "#{HydraPublicApiClient::API_URL}/userinfo").to_return(status: 401)
125+
expect(user).to be_nil
137126
end
138127
end
139128

0 commit comments

Comments
 (0)