Skip to content

Commit 75dbeeb

Browse files
authored
[shopsys] split ElasticsearchIndexException into separate ones (#3003)
1 parent 7d28afa commit 75dbeeb

20 files changed

Lines changed: 267 additions & 193 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\Elasticsearch\Exception;
6+
7+
use Exception;
8+
9+
class ElasticsearchAliasNotFoundException extends Exception
10+
{
11+
/**
12+
* @param string $alias
13+
*/
14+
public function __construct(string $alias)
15+
{
16+
parent::__construct(
17+
sprintf('Index with alias "%s" was not found.', $alias),
18+
);
19+
}
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\Elasticsearch\Exception;
6+
7+
use Exception;
8+
9+
class ElasticsearchBulkUpdateException extends Exception
10+
{
11+
/**
12+
* @param string $indexName
13+
* @param array $errors
14+
*/
15+
public function __construct(string $indexName, array $errors)
16+
{
17+
parent::__construct(sprintf(
18+
'One or more items return error when updating "%s":' . PHP_EOL . '"%s"',
19+
$indexName,
20+
json_encode($errors, JSON_THROW_ON_ERROR),
21+
));
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\Elasticsearch\Exception;
6+
7+
use Exception;
8+
9+
class ElasticsearchCannotReadDefinitionFileException extends Exception
10+
{
11+
/**
12+
* @param string $definitionFilepath
13+
*/
14+
public function __construct(string $definitionFilepath)
15+
{
16+
parent::__construct(sprintf(
17+
'Can\'t read definition file at path "%s". Please check that file exists and has permissions for reading.',
18+
$definitionFilepath,
19+
));
20+
}
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\Elasticsearch\Exception;
6+
7+
use Exception;
8+
9+
class ElasticsearchCreateAliasException extends Exception
10+
{
11+
/**
12+
* @param string $alias
13+
* @param array $error
14+
*/
15+
public function __construct(string $alias, array $error)
16+
{
17+
parent::__construct(sprintf(
18+
'Error when creating alias "%s":' . PHP_EOL . '"%s"',
19+
$alias,
20+
json_encode($error, JSON_THROW_ON_ERROR),
21+
));
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\Elasticsearch\Exception;
6+
7+
use Exception;
8+
9+
class ElasticsearchCreateIndexException extends Exception
10+
{
11+
/**
12+
* @param string $indexName
13+
* @param array $error
14+
*/
15+
public function __construct(string $indexName, array $error)
16+
{
17+
parent::__construct(sprintf(
18+
'Error when creating index "%s":' . PHP_EOL . '"%s"',
19+
$indexName,
20+
json_encode($error, JSON_THROW_ON_ERROR),
21+
));
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\Elasticsearch\Exception;
6+
7+
use Exception;
8+
9+
class ElasticsearchDeleteIndexException extends Exception
10+
{
11+
/**
12+
* @param string $indexName
13+
* @param array $error
14+
*/
15+
public function __construct(string $indexName, array $error)
16+
{
17+
parent::__construct(sprintf(
18+
'Error when creating index "%s":' . PHP_EOL . '"%s"',
19+
$indexName,
20+
json_encode($error, JSON_THROW_ON_ERROR),
21+
));
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\Elasticsearch\Exception;
6+
7+
use Exception;
8+
9+
class ElasticsearchIndexAliasAlreadyExistsException extends Exception
10+
{
11+
/**
12+
* @param string $indexAlias
13+
*/
14+
public function __construct(string $indexAlias)
15+
{
16+
parent::__construct(sprintf(
17+
'There is an index for alias "%s" already. You have to migrate it first due to different definition.',
18+
$indexAlias,
19+
));
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\Elasticsearch\Exception;
6+
7+
use Exception;
8+
9+
class ElasticsearchIndexAliasNotFoundException extends Exception
10+
{
11+
/**
12+
* @param string $aliasName
13+
*/
14+
public function __construct(string $aliasName)
15+
{
16+
parent::__construct(sprintf(
17+
'Index with alias "%s" was not found.',
18+
$aliasName,
19+
));
20+
}
21+
}

src/Component/Elasticsearch/Exception/ElasticsearchIndexException.php

Lines changed: 0 additions & 130 deletions
This file was deleted.

src/Component/Elasticsearch/Exception/ElasticsearchIndexAlreadyExistsException.php renamed to src/Component/Elasticsearch/Exception/ElasticsearchIndexNotFoundException.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44

55
namespace Shopsys\FrameworkBundle\Component\Elasticsearch\Exception;
66

7-
class ElasticsearchIndexAlreadyExistsException extends ElasticsearchIndexException
7+
use Exception;
8+
9+
class ElasticsearchIndexNotFoundException extends Exception
810
{
911
/**
1012
* @param string $indexName
1113
*/
1214
public function __construct(string $indexName)
1315
{
14-
parent::__construct(sprintf('Index "%s" already exists', $indexName));
16+
parent::__construct(sprintf(
17+
'Index "%s" was not found.',
18+
$indexName,
19+
));
1520
}
1621
}

0 commit comments

Comments
 (0)