File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -60,6 +60,10 @@ private function routeClientResponseException($result): string
6060 return $ this ->formatAsConflictException ($ error );
6161 }
6262
63+ if (! isset ($ error ['error ' ]['type ' ])) {
64+ return $ result ->getMessage ();
65+ }
66+
6367 return match ($ error ['error ' ]['type ' ]) {
6468 'search_phase_execution_exception ' => $ this ->formatSearchPhaseExecutionException ($ error ),
6569 'script_exception ' => $ this ->formatScriptException ($ error ),
Original file line number Diff line number Diff line change 1919
2020Root Cause Type: parsing_exception
2121Root Cause Reason: Unknown key for a START_ARRAY in [query] ' );
22+
23+ it ('handles error responses without error.type structure ' , function () {
24+ $ body = json_encode (['status ' => 400 , 'message ' => 'Something went wrong ' ]);
25+ $ response = new \GuzzleHttp \Psr7 \Response (400 , [], $ body );
26+ $ previous = new \Elastic \Elasticsearch \Exception \ClientResponseException ($ body , 400 );
27+ $ previous ->setResponse ($ response );
28+
29+ $ exception = new QueryException ($ previous );
30+
31+ expect ($ exception )->toBeInstanceOf (QueryException::class)
32+ ->and ($ exception ->getMessage ())->toBe ($ body );
33+ });
34+
35+ it ('handles error responses with null json body ' , function () {
36+ $ response = new \GuzzleHttp \Psr7 \Response (400 , [], 'not json at all ' );
37+ $ previous = new \Elastic \Elasticsearch \Exception \ClientResponseException ('not json at all ' , 400 );
38+ $ previous ->setResponse ($ response );
39+
40+ $ exception = new QueryException ($ previous );
41+
42+ expect ($ exception )->toBeInstanceOf (QueryException::class)
43+ ->and ($ exception ->getMessage ())->toBe ('not json at all ' );
44+ });
You can’t perform that action at this time.
0 commit comments