Skip to content

Commit

Permalink
Handle api exception in Gitea status reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
krauselukas authored and eduardoj committed Sep 27, 2022
1 parent 3415d5e commit 5ab04ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/api/app/services/gitea_status_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ def call
sha: @event_subscription_payload[:commit_sha],
state: @state, **status_options)
@workflow_run.save_scm_report_success(request_context) if @workflow_run.present?
rescue Faraday::ConnectionFailed => e
@workflow_run.save_scm_report_failure("Failed to report back to Gitea: #{e.message}", request_context) if @workflow_run.present?
rescue GiteaAPI::V1::Client::GiteaApiError => e
rescue_with_handler(e) || raise(e)
end

private

# TODO: extract to a parent class
def status_options
if @initial_report
{ context: 'OBS SCM/CI Workflow Integration started',
Expand Down
7 changes: 7 additions & 0 deletions src/api/app/services/scm_exception_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class SCMExceptionHandler
log_to_workflow_run(exception, 'GitLab') if @workflow_run.present?
end

rescue_from GiteaAPI::V1::Client::NotFoundError,
GiteaAPI::V1::Client::BadRequestError,
GiteaAPI::V1::Client::UnauthorizedError,
GiteaAPI::V1::Client::ForbiddenError do |exception|
log_to_workflow_run(exception, 'Gitea') if @workflow_run.present?
end

def initialize(event_payload, event_subscription_payload, scm_token, workflow_run = nil)
@event_payload = event_payload.deep_symbolize_keys
@event_subscription_payload = event_subscription_payload.deep_symbolize_keys
Expand Down

0 comments on commit 5ab04ff

Please sign in to comment.