Skip to content

Commit

Permalink
send facebook response with exception message (#395)
Browse files Browse the repository at this point in the history
We are not sure how this will affect issue grouping in Sentry, but
want to test it out. It's important to be able to access the facebook
error data.
  • Loading branch information
vasconsaurus authored Sep 26, 2023
1 parent 8457348 commit 02411d3
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/models/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,22 @@ def verify_facebook_metrics_response(url, response)

error = JSON.parse(response.body)['error']
is_retryable = (RETRYABLE_FACEBOOK_ERROR_CODES + FACEBOOK_RATE_LIMIT_CODES).include?(error['code'].to_i)
fb_error_hash = {
'app.api_key' => ApiKey.current&.id,
'facebook.metrics.error.code' => error['code'],
'facebook.metrics.error.message' => error['message'],
'facebook.metrics.url' => url,
'facebook.metrics.retryable' => is_retryable
}

Rails.logger.warn level: 'WARN', message: "Facebook metrics error: #{error['code']} - #{error['message']}", url: url, key_id: ApiKey.current&.id, error: error, retryable: is_retryable
TracingService.set_error_status(
"Facebook metrics error",
attributes: {
'app.api_key' => ApiKey.current&.id,
'facebook.metrics.error.code' => error['code'],
'facebook.metrics.error.message' => error['message'],
'facebook.metrics.url' => url,
'facebook.metrics.retryable' => is_retryable
}
attributes: fb_error_hash
)
if is_retryable
@locker.lock(3600) if FACEBOOK_RATE_LIMIT_CODES.include?(error['code'].to_i)
raise Pender::Exception::RetryLater, 'Metrics request failed'
raise Pender::Exception::RetryLater, "Metrics request failed.\n#{fb_error_hash.to_json}"
end
end

Expand Down

0 comments on commit 02411d3

Please sign in to comment.