Skip to content

feat(exceptions): add typed exception hierarchy with machine error codes#5

Merged
vitormattos merged 8 commits intomainfrom
feat/error-taxonomy
Mar 22, 2026
Merged

feat(exceptions): add typed exception hierarchy with machine error codes#5
vitormattos merged 8 commits intomainfrom
feat/error-taxonomy

Conversation

@vitormattos
Copy link
Member

Summary

Completes Phase 1 of the nfse-php contract layer by introducing a typed
exception hierarchy with machine-readable error codes.

New types

  • NfseErrorCode — backed enum (string) with five machine error codes:
    NETWORK_FAILURE, INVALID_RESPONSE, ISSUANCE_REJECTED,
    CANCELLATION_REJECTED, QUERY_FAILED
  • GatewayException — base for 4xx/5xx gateway errors; carries errorCode,
    httpStatus, and upstreamPayload (raw decoded response body for diagnostics)
  • NetworkException — connectivity failures and unparseable responses
  • IssuanceException extends GatewayException — gateway rejected an emit
  • CancellationException extends GatewayException — gateway rejected a cancel
  • QueryException extends GatewayException — gateway returned an error for a query

NfseClient changes

  • request() renamed to fetchAndDecode(): now returns array{int, array}
    (HTTP status + decoded body) instead of a bare decoded array
  • HTTP status is extracted from $http_response_header (set by PHP in local
    scope when using the HTTP wrapper)
  • emit / query / cancel check the status and throw the appropriate typed
    exception before delegating to parseReceiptResponse
  • delete() return type changed from void to array{int, array} so callers
    can inspect the cancellation status

Validation

  • composer test:unit — 19/19 ✓ (6 new typed-exception tests)
  • composer cs:fix — 0 files changed
  • composer psalm — No errors found

Signed-off-by: Vitor Mattos <vitor@php.rio>
Signed-off-by: Vitor Mattos <vitor@php.rio>
Signed-off-by: Vitor Mattos <vitor@php.rio>
Signed-off-by: Vitor Mattos <vitor@php.rio>
Signed-off-by: Vitor Mattos <vitor@php.rio>
@vitormattos vitormattos merged commit 53d2193 into main Mar 22, 2026
10 checks passed
@vitormattos vitormattos deleted the feat/error-taxonomy branch March 22, 2026 02:49
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