Skip to content

Commit

Permalink
Pass along information to editor when node already exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
rasben committed Dec 17, 2024
1 parent 5b13525 commit becd376
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\bnf_client\Services;

use Drupal\bnf\BnfStateEnum;
use Drupal\bnf\Exception\AlreadyExistsException;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\node\NodeInterface;
Expand Down Expand Up @@ -95,6 +96,11 @@ public function exportNode(NodeInterface $node): void {
$this->logger->error(
'Failed at exporting node to BNF server. @message',
['@message' => $message]);

if ($status === 'duplicate') {
throw new AlreadyExistsException();
}

throw new \Exception($message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\bnf_server\Plugin\GraphQL\DataProducer;

use Drupal\bnf\Exception\AlreadyExistsException;
use Drupal\bnf\Services\BnfImporter;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
Expand Down Expand Up @@ -79,7 +80,7 @@ public function __construct(
*
* @return string[]
* An associative array containing:
* - 'status': 'success' or 'failure'.
* - 'status': 'success', 'failure', 'duplicate'.
* - 'message': A detailed message about the result of the operation.
*/
public function resolve(string $uuid, string $callbackUrl): array {
Expand Down Expand Up @@ -111,7 +112,7 @@ public function resolve(string $uuid, string $callbackUrl): array {
]);

return [
'status' => 'failure',
'status' => ($e instanceof AlreadyExistsException) ? 'duplicate' : 'failure',
'message' => $e->getMessage(),
];
}
Expand Down

0 comments on commit becd376

Please sign in to comment.