-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathElasticsearchException.php
151 lines (133 loc) · 5.18 KB
/
ElasticsearchException.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php declare(strict_types=1);
namespace Shopware\Elasticsearch;
use Shopware\Core\Framework\HttpException;
use Shopware\Core\Framework\Log\Package;
use Symfony\Component\HttpFoundation\Response;
#[Package('core')]
class ElasticsearchException extends HttpException
{
public const DEFINITION_NOT_FOUND = 'ELASTICSEARCH__DEFINITION_NOT_FOUND';
public const UNSUPPORTED_DEFINITION = 'ELASTICSEARCH__UNSUPPORTED_DEFINITION';
public const INDEXING_ERROR = 'ELASTICSEARCH__INDEXING_ERROR';
public const NESTED_AGGREGATION_MISSING = 'ELASTICSEARCH__NESTED_FILTER_AGGREGATION_MISSING';
public const UNSUPPORTED_AGGREGATION = 'ELASTICSEARCH__UNSUPPORTED_AGGREGATION';
public const UNSUPPORTED_FILTER = 'ELASTICSEARCH__UNSUPPORTED_FILTER';
public const NESTED_AGGREGATION_PARSE_ERROR = 'ELASTICSEARCH__NESTED_AGGREGATION_PARSE_ERROR';
public const PARENT_FILTER_ERROR = 'ELASTICSEARCH__PARENT_FILTER_ERROR';
public const SERVER_NOT_AVAILABLE = 'ELASTICSEARCH__SERVER_NOT_AVAILABLE';
public const EMPTY_QUERY = 'ELASTICSEARCH__EMPTY_QUERY';
public const EMPTY_INDEXING_REQUEST = 'ELASTICSEARCH__EMPTY_INDEXING_REQUEST';
public const AWS_CREDENTIALS_NOT_FOUND = 'ELASTICSEARCH__AWS_CREDENTIALS_NOT_FOUND';
public static function definitionNotFound(string $definition): self
{
return new self(
Response::HTTP_BAD_REQUEST,
self::DEFINITION_NOT_FOUND,
'Definition {{ definition }} not found',
['definition' => $definition]
);
}
public static function unsupportedElasticsearchDefinition(string $definition): self
{
return new self(
Response::HTTP_BAD_REQUEST,
self::UNSUPPORTED_DEFINITION,
'Definition {{ definition }} is not supported for elasticsearch',
['definition' => $definition]
);
}
/**
* @param array{reason: string}|array{reason: string}[] $items
*/
public static function indexingError(array $items): self
{
$esErrors = \PHP_EOL . implode(\PHP_EOL, array_column($items, 'reason'));
$exceptionMessage = 'Following errors occurred while indexing: {{ messages }}';
if (\in_array('mapper_parsing_exception', array_column($items, 'type'), true)) {
$exceptionMessage = 'Some fields are mapped to incorrect types. Please reset the index and rebuild it. Full errors: {{ messages }}';
}
return new self(
Response::HTTP_INTERNAL_SERVER_ERROR,
self::INDEXING_ERROR,
$exceptionMessage,
['messages' => $esErrors]
);
}
public static function nestedAggregationMissingInFilterAggregation(string $aggregation): self
{
return new self(
Response::HTTP_BAD_REQUEST,
self::NESTED_AGGREGATION_MISSING,
'Filter aggregation {{ aggregation }} contains no nested aggregation.',
['aggregation' => $aggregation]
);
}
public static function unsupportedAggregation(string $aggregationClass): self
{
return new self(
Response::HTTP_BAD_REQUEST,
self::UNSUPPORTED_AGGREGATION,
'Provided aggregation of class {{ aggregationClass }} is not supported',
['aggregationClass' => $aggregationClass]
);
}
public static function unsupportedFilter(string $filterClass): self
{
return new self(
Response::HTTP_BAD_REQUEST,
self::UNSUPPORTED_FILTER,
'Provided filter of class {{ filterClass }} is not supported',
['filterClass' => $filterClass]
);
}
public static function nestedAggregationParseError(string $aggregationName): self
{
return new self(
Response::HTTP_BAD_REQUEST,
self::NESTED_AGGREGATION_PARSE_ERROR,
'Nested filter aggregation {{ aggregation }} can not be parsed.',
['aggregation' => $aggregationName]
);
}
public static function parentFilterError(string $filter): self
{
return new self(
Response::HTTP_BAD_REQUEST,
self::PARENT_FILTER_ERROR,
'Expected nested+filter+reverse pattern for parsed filter {{ filter }} to set next parent correctly.',
['filter' => $filter]
);
}
public static function serverNotAvailable(): self
{
return new self(
Response::HTTP_INTERNAL_SERVER_ERROR,
self::SERVER_NOT_AVAILABLE,
'Elasticsearch server is not available'
);
}
public static function emptyQuery(): self
{
return new self(
Response::HTTP_INTERNAL_SERVER_ERROR,
self::EMPTY_QUERY,
'Empty query provided'
);
}
public static function awsCredentialsNotFound(): self
{
return new self(
Response::HTTP_INTERNAL_SERVER_ERROR,
self::AWS_CREDENTIALS_NOT_FOUND,
'Could not get AWS credentials'
);
}
public static function emptyIndexingRequest(): self
{
return new self(
Response::HTTP_BAD_REQUEST,
self::EMPTY_INDEXING_REQUEST,
'Empty indexing request provided'
);
}
}