Skip to content
Snippets Groups Projects
Commit 9b04fdfd authored by Aaron Bauman's avatar Aaron Bauman
Browse files

Fix test

parent 1faf3b79
No related branches found
No related tags found
No related merge requests found
......@@ -20,14 +20,14 @@ use Drupal\salesforce_mapping\MappingConstants;
* "storage" = "Drupal\salesforce_mapping\SalesforceMappingStorage",
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "access" = "Drupal\salesforce_mapping\SalesforceMappingAccessController",
* "list_builder" = "Drupal\salesforce_mapping\SalesforceMappingList",
* "list_builder" = "Drupal\salesforce_mapping_ui\SalesforceMappingList",
* "form" = {
* "add" = "Drupal\salesforce_mapping\Form\SalesforceMappingAddForm",
* "edit" = "Drupal\salesforce_mapping\Form\SalesforceMappingEditForm",
* "disable" = "Drupal\salesforce_mapping\Form\SalesforceMappingDisableForm",
* "delete" = "Drupal\salesforce_mapping\Form\SalesforceMappingDeleteForm",
* "enable" = "Drupal\salesforce_mapping\Form\SalesforceMappingEnableForm",
* "fields" = "Drupal\salesforce_mapping\Form\SalesforceMappingFieldsForm",
* "add" = "Drupal\salesforce_mapping_ui\Form\SalesforceMappingAddForm",
* "edit" = "Drupal\salesforce_mapping_ui\Form\SalesforceMappingEditForm",
* "disable" = "Drupal\salesforce_mapping_ui\Form\SalesforceMappingDisableForm",
* "delete" = "Drupal\salesforce_mapping_ui\Form\SalesforceMappingDeleteForm",
* "enable" = "Drupal\salesforce_mapping_ui\Form\SalesforceMappingEnableForm",
* "fields" = "Drupal\salesforce_mapping_ui\Form\SalesforceMappingFieldsForm",
* }
* },
* admin_permission = "administer salesforce mapping",
......
......@@ -94,15 +94,25 @@ abstract class SalesforceMappingFormBase extends EntityForm {
* TRUE if Salesforce endpoint (or cache) responded correctly.
*/
protected function ensureConnection($method = 'objects', $arg = []) {
try {
$this->client->{$method}($arg);
$message = '';
if ($this->client->isReady()) {
try {
$this->client->{$method}($arg);
return TRUE;
}
catch (\Exception $e) {
// Fall through.
$message = $e->getMessage() ?: get_class($e);
}
}
catch (\Exception $e) {
$href = new Url('salesforce.auth_config');
$this->messenger()->addError($this->t('Error when connecting to Salesforce. Please <a href="@href">check your credentials</a> and try again: %message', ['@href' => $href->toString(), '%message' => $e->getMessage() ?: get_class($e)]), 'error');
return FALSE;
}
return TRUE;
$href = new Url('salesforce.auth_config');
$this->messenger()
->addError($this->t('Error when connecting to Salesforce. Please <a href="@href">check your credentials</a> and try again: %message', [
'@href' => $href->toString(),
'%message' => $message,
]), 'error');
return FALSE;
}
/**
......
......@@ -145,6 +145,13 @@ class RestClient implements RestClientInterface {
return $this;
}
public function isReady() {
if (!$this->authProvider || !$this->authToken) {
return FALSE;
}
return TRUE;
}
/**
* {@inheritdoc}
*/
......
......@@ -11,6 +11,14 @@ use Drupal\salesforce\SelectQueryResult;
*/
interface RestClientInterface {
/**
* Check if the client is ready to perform API calls.
*
* @return bool
* TRUE if the client is ready to perform API calls. Otherwise FALSE.
*/
public function isReady();
/**
* Make a call to the Salesforce REST API.
*
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment