WS-6 v1.3-delta D1 — Foundation delta (data layer + exception hierarchy) #10
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\FormBuilder\Bindings;
|
||||
|
||||
use App\Exceptions\FormBuilder\FormBindingApplicatorException;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Maps a Throwable to a failure_response_code string.
|
||||
*
|
||||
* Used by both ApplyBindingsOnFormSubmit::handle's catch block (D2) and
|
||||
* FormFailureRetryService::recordFailure (D2 update). Centralised so the
|
||||
* listener and the retry-service produce identical classifications and a
|
||||
* single behaviour change requires a single edit.
|
||||
*
|
||||
* Resolution order:
|
||||
* 1. If the Throwable is a FormBindingApplicatorException, return its reasonCode().
|
||||
* Subclass dispatch handles SchemaConfig / Infra / DataIntegrity / Timeout
|
||||
* (Timeout extends Infra so it inherits 'temporary_error').
|
||||
* 2. Otherwise, return 'unknown_error' — anything outside the hierarchy
|
||||
* (database connection lost not surfaced as Infra, generic RuntimeException
|
||||
* from a non-applicator code path, IdentityMatchInvariantViolation if it
|
||||
* somehow leaks here) is unknown from the response-shape perspective.
|
||||
*
|
||||
* Per RFC-WS-6 §Q3 v1.3 addition 2.
|
||||
*/
|
||||
final class FormBindingExceptionClassifier
|
||||
{
|
||||
public static function classify(Throwable $exception): string
|
||||
{
|
||||
if ($exception instanceof FormBindingApplicatorException) {
|
||||
return $exception->reasonCode();
|
||||
}
|
||||
|
||||
return 'unknown_error';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user