has_errors() ) { throw WPError::from_error( $maybe_error ); } } /** * Create a WP_Error from an exception. * * @param Throwable $e * @param string $code * @param array $data * * @return WP_Error */ protected function error_from_exception( Throwable $e, string $code, array $data = [] ): WP_Error { return new WP_Error( $code, $data['message'] ?? $e->getMessage(), $data ); } /** * Try to decode a JSON string. * * @param string $message * * @return array * @throws Exception When the JSON could not be decoded. */ protected function json_decode_message( string $message ): array { $decoded = json_decode( $message, true ); if ( null === $decoded || JSON_ERROR_NONE !== json_last_error() ) { throw new Exception( 'Could not decode JSON' ); } return $decoded; } }