Skip to content

Unifies exception handling with common interface - #64

Merged
SergkeiM merged 1 commit into
masterfrom
feature/exceptions
Aug 14, 2026
Merged

SergkeiM merged 1 commit into
masterfrom
feature/exceptions

Conversation

@SergkeiM

Copy link
Copy Markdown
Owner

Introduces Cloudflare\Contracts\ExceptionInterface to provide a single, consistent way to catch all exceptions originating from this package. This allows developers to simplify error handling by using a single catch (ExceptionInterface $e) block for all package-related failures, regardless of their specific type or origin.

  • Simplifies error handling: Catches both HTTP client errors and internal client errors (e.g., invalid arguments, bad configuration) under one unified interface.
  • Maintains backward compatibility: Existing catch blocks for native SPL exception types (e.g., \InvalidArgumentException, \BadMethodCallException) continue to work as individual exceptions still extend their original parents.
  • Refactors MissingArgumentException: Changes its parent from \ErrorException to InvalidArgumentException for better logical grouping and consistency within the exception hierarchy.
  • Updates documentation: Adds a new section to the usage guide explaining how to leverage the new interface for comprehensive exception catching.
  • Includes comprehensive test coverage: Verifies that all package exceptions implement the new interface and that existing exception behaviors are preserved.

Introduces `Cloudflare\Contracts\ExceptionInterface`, implemented by every
exception thrown by the client. This allows consumers to catch all package
exceptions with a single `catch` block, simplifying error handling.

Existing `catch` blocks for native PHP exceptions (e.g., `InvalidArgumentException`)
remain fully functional as the individual exceptions retain their original parents.
@SergkeiM
SergkeiM merged commit 73c5829 into master Aug 14, 2026
8 checks passed
@SergkeiM
SergkeiM deleted the feature/exceptions branch August 14, 2026 20:35
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.

1 participant