Skip to content

Add typed error method to challenges#267

Merged
unixcharles merged 2 commits intounixcharles:masterfrom
nckslvrmn:add-typed-error-method-to-challenges
Mar 9, 2026
Merged

Add typed error method to challenges#267
unixcharles merged 2 commits intounixcharles:masterfrom
nckslvrmn:add-typed-error-method-to-challenges

Conversation

@nckslvrmn
Copy link
Copy Markdown
Contributor

Per RFC 8555 §7.1.6 and §8.2, when a challenge fails validation the CA sets status: "invalid" and includes an error field with the same problem document format (type, detail) used in HTTP error responses. Currently the gem stores this as a raw hash, requiring consumers to manually parse it and map type to the correct error class — duplicating the same logic the gem already uses internally for HTTP-level errors.

Changes

  • Added typed_error method to Acme::Client::Resources::Challenges::Base
  • Uses the existing ACME_ERRORS mapping to return a properly typed error instance (e.g. Acme::Client::Error::Dns, Acme::Client::Error::Unauthorized)
  • Falls back to Acme::Client::Error for unknown error types
  • Returns nil when no error is present
  • The existing error attr (raw hash) is unchanged

Usage

challenge.reload

if challenge.status == 'invalid'
  err = challenge.typed_error
  case err
  when Acme::Client::Error::Dns
    # transient DNS failure, maybe retry
  when Acme::Client::Error::Caa
    # CAA prevents issuance, don't retry
  end
end

No breaking changes

Purely additive. The raw error hash continues to be available as before.

@unixcharles
Copy link
Copy Markdown
Owner

You could switch on error['type'] too but I could see the user wanting to raise the error too.

@unixcharles unixcharles merged commit 0f496c6 into unixcharles:master Mar 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants