mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-19 22:15:14 +00:00
Handle 401 from github
Fixes https://github.com/hackclub/hackatime/issues/293
This commit is contained in:
parent
3204e41be8
commit
883acfde52
2 changed files with 11 additions and 2 deletions
|
|
@ -89,6 +89,10 @@ class ProcessCommitJob < ApplicationJob
|
|||
end
|
||||
Rails.logger.info "[ProcessCommitJob] Successfully processed commit #{api_commit_sha} for User ##{user.id}."
|
||||
|
||||
elsif response.status.code == 401 # Unauthorized
|
||||
Rails.logger.error "[ProcessCommitJob] Unauthorized (401) for User ##{user.id}. GitHub token expired/invalid. URL: #{commit_api_url}"
|
||||
user.update!(github_access_token: nil)
|
||||
Rails.logger.info "[ProcessCommitJob] Cleared invalid GitHub token for User ##{user.id}. User will need to re-authenticate."
|
||||
elsif response.status.code == 404
|
||||
Rails.logger.warn "[ProcessCommitJob] Commit #{commit_sha} not found (404) at #{commit_api_url} for User ##{user.id}."
|
||||
elsif response.status.code == 403 # Forbidden, could be rate limit or permissions
|
||||
|
|
@ -102,7 +106,7 @@ class ProcessCommitJob < ApplicationJob
|
|||
end
|
||||
else
|
||||
Rails.logger.error "[ProcessCommitJob] GitHub API error for User ##{user.id}. Status: #{response.status}. URL: #{commit_api_url}. Response: #{response.body.to_s.truncate(500)}"
|
||||
raise "GitHub API Error: Status #{response.status}" if response.status.server_error? || response.status.code == 401 # Trigger retry for server errors or auth issues
|
||||
raise "GitHub API Error: Status #{response.status}" if response.status.server_error? # Trigger retry for server errors
|
||||
end
|
||||
|
||||
rescue HTTP::Error => e # Covers TimeoutError, ConnectionError
|
||||
|
|
|
|||
|
|
@ -42,6 +42,11 @@ class PullRepoCommitsJob < ApplicationJob
|
|||
if response.status.success?
|
||||
commits_data = response.parse
|
||||
process_commits(user, commits_data, repository)
|
||||
|
||||
elsif response.status.code == 401 # Unauthorized
|
||||
Rails.logger.error "[PullRepoCommitsJob] Unauthorized (401) for User ##{user.id}. GitHub token expired/invalid. URL: #{commit_api_url}"
|
||||
user.update!(github_access_token: nil)
|
||||
Rails.logger.info "[PullRepoCommitsJob] Cleared invalid GitHub token for User ##{user.id}. User will need to re-authenticate."
|
||||
elsif response.status.code == 404
|
||||
Rails.logger.warn "[PullRepoCommitsJob] Repository #{owner}/#{repo} not found (404) for User ##{user.id}."
|
||||
elsif response.status.code == 403 # Forbidden, could be rate limit or permissions
|
||||
|
|
@ -55,7 +60,7 @@ class PullRepoCommitsJob < ApplicationJob
|
|||
end
|
||||
else
|
||||
Rails.logger.error "[PullRepoCommitsJob] GitHub API error for User ##{user.id}. Status: #{response.status}. Response: #{response.body.to_s.truncate(500)}"
|
||||
raise "GitHub API Error: Status #{response.status}" if response.status.server_error? || response.status.code == 401
|
||||
raise "GitHub API Error: Status #{response.status}" if response.status.server_error?
|
||||
end
|
||||
|
||||
rescue HTTP::Error => e
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue