Closed rvdsteege closed 1 year ago
A possible solution is:
$data['options'] = [];
try {
$data['options'] = $this->get_flat_options();
} catch ( \Exception $e ) {
$data['error'] = $e->getMessage();
}
return $data;
But the question is also why is there an IDealIssuerSelectField
instance in Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry->data
?
I know we use the field JSON for the registerPaymentMethod
content
property:
The field.options
property is directly injected in the WordPress <SelectControl options={ field.options } />
component:
We currently also use <BaseControl />
, is there a default way to display errors for these control components? Should we add a <Notice status="error">An unknown error occurred.</Notice>
when field.error
is set? Is field.error
a common property for field errors?
Apart from this I think it is correct to add a try catch in jsonSerialize
?
I just came across a broken block editor (Classic block) because a fatal error occurred during JSON serialization of a field.
https://github.com/pronamic/wp-pay-core/blob/7baee62c4eebd8854cd9ae28dca5e6e1a45cb1b0/src/Fields/SelectField.php#L100-L112
The gateway configuration had invalid credentials and the option were retrieved through a
IDealIssuerSelectField
class.The issue was triggered from WooCommerce via the JSON encode of
$this->data
in https://github.com/woocommerce/woocommerce-blocks/blob/2ff8573d5426ebee180e50539f113c211362d1b9/src/Assets/AssetDataRegistry.php#L348-L373Internal Help Scout ticket: https://secure.helpscout.net/conversation/2036688566/24611