Skip to content
Snippets Groups Projects
Unverified Commit 056dd588 authored by Mike McQuaid's avatar Mike McQuaid
Browse files

utils/github: add ValidationFailedError.

These have specific errors returned so would be more useful to output.
parent 473155e1
No related branches found
No related tags found
No related merge requests found
......@@ -45,7 +45,7 @@ module GitHub
class AuthenticationFailedError < Error
def initialize(github_message)
@github_message = github_message
message = "GitHub #{github_message}\n"
message = "GitHub #{github_message}:"
if ENV["HOMEBREW_GITHUB_API_TOKEN"]
message << <<~EOS
HOMEBREW_GITHUB_API_TOKEN may be invalid or expired; check:
......@@ -65,6 +65,18 @@ module GitHub
end
end
class ValidationFailedError < Error
def initialize(github_message, errors)
@github_message = if errors.empty?
github_message
else
"#{github_message}: #{errors}"
end
super(@github_message)
end
end
def api_credentials
@api_credentials ||= begin
if ENV["HOMEBREW_GITHUB_API_TOKEN"]
......@@ -231,6 +243,9 @@ module GitHub
raise AuthenticationFailedError, message
when "404"
raise HTTPNotFoundError, message
when "422"
errors = json&.[]("errors") || []
raise ValidationFailedError.new(message, errors)
else
raise Error, message
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment